Created
January 26, 2017 16:41
-
-
Save JonTheNiceGuy/41cc5d9c38f410889e6ec87a972b2b9e to your computer and use it in GitHub Desktop.
How to define multiple NICs on a host in Ansible with K5. Note this is redacted from my own code, so yours may need some tweaking and changes!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
compute_images: | |
REDACTED: | |
name: "REDACTED" | |
compute_types: | |
REDACTED: | |
name: "REDACTED" | |
az: | |
1a: | |
name: "1a" | |
region: "1" | |
keypair: "1a" | |
Networks: | |
External_1a: | |
name: "External-1a" | |
shortname: "External" | |
az: "{{ az.1a }}" | |
cidr: "192.0.2.0/26" | |
gateway_ip: "192.0.2.1" | |
ext_net: "az1a-net1" | |
DMZ_1a: | |
name: "DMZ-1A" | |
shortname: "DMZ" | |
az: "{{ az.1a }}" | |
cidr: "192.0.2.64/26" | |
gateway_ip: "192.0.2.65" | |
Compute_Hosts: | |
ThisHost: | |
name: "ThisHost" | |
image: compute_images.REDACTED.name | |
flavor: compute_types.REDACTED.name | |
az: "{{ az.1a }}" | |
log_size: "150" | |
os_size: "10" | |
ports: | |
- network: "{{ Networks.External_1a }}" | |
- network: "{{ Networks.DMZ_1a }}" | |
fixed_ip: | |
- "{{ Networks.DMZ_1a.gateway_ip }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: "Host Port Creation" | |
k5_port: | |
state: present | |
name: "{{ item.0.name }}-Port-{{ item.1.network.name }}" | |
network_name: "{{ item.1.network.name }}" | |
subnet_name: "{{ item.1.network.name }}" | |
availability_zone: "{{ item.0.az.name }}" | |
fixed_ip: "{{ item.1.fixed_ip|default(omit) }}" | |
allowed_address_pairs: "{{ item.1.allowed_address_pairs|default(omit) }}" | |
security_groups: "{{ item.1.security_group|default('default') }}" | |
k5_auth: "{{ k5_auth_reg.k5_auth_facts }}" | |
with_subelements: | |
- "{{ Compute_Hosts }}" | |
- ports | |
- name: "Create Log Storage" | |
os_volume: | |
display_name: "{{ item.value.name }}-Log-Volume" | |
availability_zone: "{{ item.value.az.name }}" | |
state: present | |
size: "{{ item.value.log_size }}" | |
region_name: "{{ item.value.az.region }}" | |
with_dict: "{{ Compute_Hosts }}" | |
when: item.value.log_size is defined | |
- name: "Create host" | |
os_server: | |
name: "{{ item.value.name }}" | |
state: present | |
availability_zone: "{{ item.value.az.name }}" | |
image: "{{ item.value.image_name }}" | |
flavor: "{{ item.value.flavor }}" | |
key_name: "{{ item.value.az.keypair }}" | |
nics: "[{%- for nwname in item.value.ports -%}{'port-name': '{{ item.value.name }}-Port-{{nwname.network.name}}'}{%- if not loop.last -%}, {%- endif -%} {%- endfor -%}]" | |
volume_size: "{{ item.value.os_size }}" | |
boot_from_volume: yes | |
terminate_volume: yes | |
volumes: | |
- "{{ item.value.name }}-Log-Volume" | |
auto_ip: no | |
with_dict: "{{ Compute_Hosts }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That looks spot on matey.
In context this makes sense now.
nics: "[{%- for nwname in item.value.ports -%}{'port-name': '{{ item.value.name }}-Port-{{nwname.network.name}}'}{%- if not loop.last -%}, {%- endif -%} {%- endfor -%}]"
...
with_dict: "{{ Compute_Hosts }}"