heat_template_version: 2014-10-16 parameters: config_drive_label: type: string default: config-2 discovery_metadata_key: type: string default: hardware control_flavor: type: string default: baremetal_control compute_flavor: type: string default: baremetal_compute image: type: string default: openstack-full key_name: type: string default: default control_count: type: number default: 3 compute_count: type: number default: 0 nic_count: type: number default: 4 resources: nic_config: type: OS::Heat::SoftwareConfig properties: group: ungrouped config: str_replace: template: | #!/bin/bash -v # Mount the config drive and extract the discovery data mount /dev/disk/by-label/disklabel /mnt jq -r ".metadata_key" /mnt/openstack/latest/meta_data.json > /tmp/discovery.json # Extract discovery data to make os-net-config mapping mkdir -p /etc/os-net-config echo "interface_mapping:" > /etc/os-net-config/mapping.yaml for ii in $(seq 1 num_nics) do echo "Processing nic $ii" mapped=$(jq -r ".hardware.nic$ii" /mnt/openstack/latest/meta_data.json) echo "mapped nic is $mapped" if [ $mapped != 'null' ]; then echo " nic$ii: $mapped" >> /etc/os-net-config/mapping.yaml fi done echo "persist_mapping: True" >> /etc/os-net-config/mapping.yaml # Create the required network config # Note, for less minimal templates this would probably be done via a SoftwareConfig # or StructuredConfig resource so alternate configurations (e.g bonded multiple # nics or whatever) could easily be substituted. cat > /etc/os-net-config/config.yaml << ENDOFCAT network_config: - type: interface name: nic1 use_dhcp: True - type: interface name: nic2 use_dhcp: True ENDOFCAT # Apply the config os-net-config --cleanup --no-ifup --no-ifdown # Remove the mapping file, or any subsequent run of # os-net-config will fail due to now non-existent nics rm -f /etc/os-net-config/mapping.yaml # Enable ssh as root for Puppet. sed -i -e 's/.*ssh-/ssh-/' ~root/.ssh/authorized_keys # Reboot for the renamed networking to take effect /sbin/reboot params: disklabel: { get_param: config_drive_label } metadata_key: { get_param: discovery_metadata_key } num_nics: {get_param: nic_count} server_init: type: OS::Heat::MultipartMime properties: parts: - config: {get_resource: nic_config} control_servers: type: OS::Heat::ResourceGroup properties: count: {get_param: control_count} resource_def: type: OS::Nova::Server properties: flavor: {get_param: control_flavor} image: {get_param: image} key_name: {get_param: key_name} config_drive: True user_data_format: RAW user_data: {get_resource: server_init} compute_servers: type: OS::Heat::ResourceGroup properties: count: {get_param: compute_count} resource_def: type: OS::Nova::Server properties: flavor: {get_param: compute_flavor} image: {get_param: image} key_name: {get_param: key_name} config_drive: True name: openstack%index% user_data_format: RAW user_data: {get_resource: server_init}