Fix creation of servers with on-the-fly keypairs
On 301ae3faee
refactor, I overlooked
the creation of servers with the generate_keypair flag enabled.
This change adds it back.
Change-Id: I891eba482db38e0b4f97222e37c9bd2e214571d1
This commit is contained in:
parent
301ae3faee
commit
0f933d768a
@ -1,4 +1,7 @@
|
||||
---
|
||||
- include: generate_keypair.yml
|
||||
when: generate_keypair|bool
|
||||
|
||||
- os_server:
|
||||
cloud: "{{ item_cloud.oscc_cloud|default(item_cloud.name) }}"
|
||||
state: "{{ item_server.state|default(omit) }}"
|
||||
@ -15,7 +18,7 @@
|
||||
floating_ips: "{{ item_server.floating_ips|default(omit) }}"
|
||||
image_exclude: "{{ item_server.image_exclude|default(omit) }}"
|
||||
key: "{{ item_server.key|default(omit) }}"
|
||||
key_name: "{{ item_server.key_name|default(omit) }}"
|
||||
key_name: "{{ cl_generated_keypair_name|default(item_server.key_name)|default(omit) }}"
|
||||
meta: "{{ item_server.meta|default(omit) }}"
|
||||
network: "{{ item_server.network|default(omit) }}"
|
||||
nics: "{{ item_server.nics|default(omit) }}"
|
||||
|
@ -1,168 +0,0 @@
|
||||
---
|
||||
- block:
|
||||
- name: Generate keypair name
|
||||
set_fact: cl_generated_keypair_name=launch-{{ lookup('pipe', "date +'%s'") }}
|
||||
- name: Generate SSH keys
|
||||
shell: ssh-keygen -t "{{ generate_keypair_key_type }}" -b "{{ generate_keypair_key_bits }}" -N '' -f "{{ generate_keypair_folder }}"/"{{ cl_generated_keypair_name }}"
|
||||
- name: Store public key filename path
|
||||
set_fact: cl_generated_keypair_public_key_filename={{ generate_keypair_folder}}/{{ cl_generated_keypair_name }}.pub
|
||||
- name: Store private key filename path
|
||||
set_fact: cl_generated_keypair_private_key_filename={{ generate_keypair_folder}}/{{ cl_generated_keypair_name }}
|
||||
|
||||
- name: Create OpenStack keypair {{ cl_generated_keypair_name }}
|
||||
os_keypair:
|
||||
cloud: "{{ item_cloud.oscc_cloud|default(item_cloud.name) }}"
|
||||
state: present
|
||||
name: "{{ cl_generated_keypair_name }}"
|
||||
public_key_file: "{{ cl_generated_keypair_public_key_filename }}"
|
||||
|
||||
- name: Create per-cloud servers for {{ item_cloud.name }}
|
||||
os_server:
|
||||
cloud: "{{ item_cloud.oscc_cloud|default(item_cloud.name) }}"
|
||||
state: "{{ item.state|default(omit) }}"
|
||||
name: "{{ item.name }}"
|
||||
image: "{{ item.image }}"
|
||||
auto_ip: "{{ item.auto_ip|default(omit) }}"
|
||||
boot_from_volume: "{{ item.boot_from_volume|default(omit) }}"
|
||||
boot_volume: "{{ item.boot_volume|default(omit) }}"
|
||||
config_drive: "{{ item.config_drive|default(omit) }}"
|
||||
flavor: "{{ item.flavor|default(omit) }}"
|
||||
flavor_include: "{{ item.flavor_include|default(omit) }}"
|
||||
flavor_ram: "{{ item.flavor_ram|default(omit) }}"
|
||||
floating_ip_pools: "{{ item.floating_ip_pools|default(omit) }}"
|
||||
floating_ips: "{{ item.floating_ips|default(omit) }}"
|
||||
image_exclude: "{{ item.image_exclude|default(omit) }}"
|
||||
key: "{{ item.key|default(omit) }}"
|
||||
key_name: "{{ cl_generated_keypair_name }}"
|
||||
meta: "{{ item.meta|default(omit) }}"
|
||||
network: "{{ item.network|default(omit) }}"
|
||||
nics: "{{ item.nics|default(omit) }}"
|
||||
scheduler_hints: "{{ item.scheduler_hints|default(omit) }}"
|
||||
security_groups: "{{ item.security_groups|default(omit) }}"
|
||||
terminate_volume: "{{ item.terminate_volume|default(omit) }}"
|
||||
userdata: "{{ item.userdata|default(omit) }}"
|
||||
volume_size: "{{ item.volume_size|default(omit) }}"
|
||||
volumes: "{{ item.volumes|default(omit) }}"
|
||||
with_items: "{{ item_cloud.servers|default([]) }}"
|
||||
tags:
|
||||
- servers
|
||||
register: os_server_result
|
||||
|
||||
- add_host: name={{ item.server.name }} groups=cl_servers_just_created ansible_ssh_host={{ item.server.public_v4 }}
|
||||
with_items: "{{ os_server_result.results }}"
|
||||
|
||||
- name: Create profiles servers for {{ item_cloud.name }}
|
||||
os_server:
|
||||
cloud: "{{ item_cloud.oscc_cloud|default(item_cloud.name) }}"
|
||||
state: "{{ item.1.state|default(omit) }}"
|
||||
name: "{{ item.1.name }}"
|
||||
image: "{{ item.1.image }}"
|
||||
auto_ip: "{{ item.1.auto_ip|default(omit) }}"
|
||||
boot_from_volume: "{{ item.1.boot_from_volume|default(omit) }}"
|
||||
boot_volume: "{{ item.1.boot_volume|default(omit) }}"
|
||||
config_drive: "{{ item.1.config_drive|default(omit) }}"
|
||||
flavor: "{{ item.1.flavor|default(omit) }}"
|
||||
flavor_include: "{{ item.1.flavor_include|default(omit) }}"
|
||||
flavor_ram: "{{ item.1.flavor_ram|default(omit) }}"
|
||||
floating_ip_pools: "{{ item.1.floating_ip_pools|default(omit) }}"
|
||||
floating_ips: "{{ item.1.floating_ips|default(omit) }}"
|
||||
image_exclude: "{{ item.1.image_exclude|default(omit) }}"
|
||||
key: "{{ item.1.key|default(omit) }}"
|
||||
key_name: "{{ cl_generated_keypair_name }}"
|
||||
meta: "{{ item.1.meta|default(omit) }}"
|
||||
network: "{{ item.1.network|default(omit) }}"
|
||||
nics: "{{ item.1.nics|default(omit) }}"
|
||||
scheduler_hints: "{{ item.1.scheduler_hints|default(omit) }}"
|
||||
security_groups: "{{ item.1.security_groups|default(omit) }}"
|
||||
terminate_volume: "{{ item.1.terminate_volume|default(omit) }}"
|
||||
userdata: "{{ item.1.userdata|default(omit) }}"
|
||||
volume_size: "{{ item.1.volume_size|default(omit) }}"
|
||||
volumes: "{{ item.1.volumes|default(omit) }}"
|
||||
with_subelements:
|
||||
- "{{ profiles|default([]) }}"
|
||||
- servers
|
||||
- { skip_missing: yes }
|
||||
when: "{{ item_cloud.profiles is defined and item.0.name in item_cloud.profiles }}"
|
||||
tags:
|
||||
- servers
|
||||
register: os_server_result
|
||||
|
||||
- add_host: name={{ item.server.name }} groups=cl_servers_just_created ansible_ssh_host={{ item.server.public_v4 }}
|
||||
with_items: "{{ os_server_result.results }}"
|
||||
when: generate_keypair|bool
|
||||
|
||||
- block:
|
||||
- name: Create per-cloud servers for {{ item_cloud.name }}
|
||||
os_server:
|
||||
cloud: "{{ item_cloud.oscc_cloud|default(item_cloud.name) }}"
|
||||
state: "{{ item.state|default(omit) }}"
|
||||
name: "{{ item.name }}"
|
||||
image: "{{ item.image }}"
|
||||
auto_ip: "{{ item.auto_ip|default(omit) }}"
|
||||
boot_from_volume: "{{ item.boot_from_volume|default(omit) }}"
|
||||
boot_volume: "{{ item.boot_volume|default(omit) }}"
|
||||
config_drive: "{{ item.config_drive|default(omit) }}"
|
||||
flavor: "{{ item.flavor|default(omit) }}"
|
||||
flavor_include: "{{ item.flavor_include|default(omit) }}"
|
||||
flavor_ram: "{{ item.flavor_ram|default(omit) }}"
|
||||
floating_ip_pools: "{{ item.floating_ip_pools|default(omit) }}"
|
||||
floating_ips: "{{ item.floating_ips|default(omit) }}"
|
||||
image_exclude: "{{ item.image_exclude|default(omit) }}"
|
||||
key: "{{ item.key|default(omit) }}"
|
||||
key_name: "{{ item.key_name|default(omit) }}"
|
||||
meta: "{{ item.meta|default(omit) }}"
|
||||
network: "{{ item.network|default(omit) }}"
|
||||
nics: "{{ item.nics|default(omit) }}"
|
||||
scheduler_hints: "{{ item.scheduler_hints|default(omit) }}"
|
||||
security_groups: "{{ item.security_groups|default(omit) }}"
|
||||
terminate_volume: "{{ item.terminate_volume|default(omit) }}"
|
||||
userdata: "{{ item.userdata|default(omit) }}"
|
||||
volume_size: "{{ item.volume_size|default(omit) }}"
|
||||
volumes: "{{ item.volumes|default(omit) }}"
|
||||
with_items: "{{ item_cloud.servers|default([]) }}"
|
||||
tags:
|
||||
- servers
|
||||
register: os_server_result
|
||||
|
||||
- add_host: name={{ item.server.name }} groups=cl_servers_just_created ansible_ssh_host={{ item.server.public_v4 }}
|
||||
with_items: "{{ os_server_result.results }}"
|
||||
|
||||
- name: Create profiles servers for {{ item_cloud.name }}
|
||||
os_server:
|
||||
cloud: "{{ item_cloud.oscc_cloud|default(item_cloud.name) }}"
|
||||
state: "{{ item.1.state|default(omit) }}"
|
||||
name: "{{ item.1.name }}"
|
||||
image: "{{ item.1.image }}"
|
||||
auto_ip: "{{ item.1.auto_ip|default(omit) }}"
|
||||
boot_from_volume: "{{ item.1.boot_from_volume|default(omit) }}"
|
||||
boot_volume: "{{ item.1.boot_volume|default(omit) }}"
|
||||
config_drive: "{{ item.1.config_drive|default(omit) }}"
|
||||
flavor: "{{ item.1.flavor|default(omit) }}"
|
||||
flavor_include: "{{ item.1.flavor_include|default(omit) }}"
|
||||
flavor_ram: "{{ item.1.flavor_ram|default(omit) }}"
|
||||
floating_ip_pools: "{{ item.1.floating_ip_pools|default(omit) }}"
|
||||
floating_ips: "{{ item.1.floating_ips|default(omit) }}"
|
||||
image_exclude: "{{ item.1.image_exclude|default(omit) }}"
|
||||
key: "{{ item.1.key|default(omit) }}"
|
||||
key_name: "{{ item.1.key_name|default(omit) }}"
|
||||
meta: "{{ item.1.meta|default(omit) }}"
|
||||
network: "{{ item.1.network|default(omit) }}"
|
||||
nics: "{{ item.1.nics|default(omit) }}"
|
||||
scheduler_hints: "{{ item.1.scheduler_hints|default(omit) }}"
|
||||
security_groups: "{{ item.1.security_groups|default(omit) }}"
|
||||
terminate_volume: "{{ item.1.terminate_volume|default(omit) }}"
|
||||
userdata: "{{ item.1.userdata|default(omit) }}"
|
||||
volume_size: "{{ item.1.volume_size|default(omit) }}"
|
||||
volumes: "{{ item.1.volumes|default(omit) }}"
|
||||
with_subelements:
|
||||
- "{{ profiles|default([]) }}"
|
||||
- servers
|
||||
- { skip_missing: yes }
|
||||
when: "{{ item_cloud.profiles is defined and item.0.name in item_cloud.profiles }}"
|
||||
tags:
|
||||
- servers
|
||||
register: os_server_result
|
||||
|
||||
- add_host: name={{ item.server.name }} groups=cl_servers_just_created ansible_ssh_host={{ item.server.public_v4 }}
|
||||
with_items: "{{ os_server_result.results }}"
|
||||
when: not generate_keypair|bool
|
18
tasks/generate_keypair.yml
Normal file
18
tasks/generate_keypair.yml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
- block:
|
||||
- name: Generate keypair name
|
||||
set_fact: cl_generated_keypair_name=launch-{{ lookup('pipe', "date +'%s'") }}
|
||||
- name: Generate SSH keys
|
||||
shell: ssh-keygen -t "{{ generate_keypair_key_type }}" -b "{{ generate_keypair_key_bits }}" -N '' -f "{{ generate_keypair_folder }}"/"{{ cl_generated_keypair_name }}"
|
||||
- name: Store public key filename path
|
||||
set_fact: cl_generated_keypair_public_key_filename={{ generate_keypair_folder}}/{{ cl_generated_keypair_name }}.pub
|
||||
- name: Store private key filename path
|
||||
set_fact: cl_generated_keypair_private_key_filename={{ generate_keypair_folder}}/{{ cl_generated_keypair_name }}
|
||||
|
||||
- name: Create OpenStack keypair {{ cl_generated_keypair_name }}
|
||||
os_keypair:
|
||||
cloud: "{{ item_cloud.oscc_cloud|default(item_cloud.name) }}"
|
||||
state: present
|
||||
name: "{{ cl_generated_keypair_name }}"
|
||||
public_key_file: "{{ cl_generated_keypair_public_key_filename }}"
|
||||
when: generate_keypair|bool
|
Loading…
Reference in New Issue
Block a user