Skip to content

Instantly share code, notes, and snippets.

@samvarankashyap
Created November 26, 2018 19:00
Show Gist options
  • Save samvarankashyap/e6a15a17eb20927758c0e631b8ab775e to your computer and use it in GitHub Desktop.
Save samvarankashyap/e6a15a17eb20927758c0e631b8ab775e to your computer and use it in GitHub Desktop.
- name: "provisioning/deprovisioning keypair"
os_keypair:
auth: "{{ auth_var | default(omit) }}"
name: "{{ res_def['res_name'] | default(res_def['name']) }}"
state: "{{ state }}"
wait: "yes"
register: res_def_output_nasync
when: not async
no_log: "{{ not debug_mode }}"
- name: "provisioning/deprovisioning keypair"
os_keypair:
auth: "{{ auth_var | default(omit) }}"
name: "{{ res_def['res_name'] | default(res_def['name']) }}"
state: "{{ state }}"
wait: "yes"
register: res_def_output_async
when: not async
no_log: "{{ not debug_mode }}"
- name: "Generate keyfile "
copy:
content: "{{ res_def_output_nasync['key']['private_key'] }}"
dest: "{{ default_ssh_key_path }}/{{ res_def['res_name'] | default(res_def['name']) }}.key"
when: state=="present" and res_def_output_nasync is defined and not async
no_log: "{{ debug_mode }}"
- name: "Append outputitem to topology_outputs"
set_fact:
topology_outputs_os_keypair: "{{ topology_outputs_os_keypair + [res_def_output] }}"
when: res_def_output_nasync.changed == true and state == "present" and not async
- name: "Async:: provisioning/deprovisioning keypair"
os_keypair:
auth: "{{ auth_var | default(omit) }}"
name: "{{ res_def['res_name'] | default(res_def['name']) }}"
state: "{{ state }}"
wait: "yes"
register: res_def_output_async
async: "{{ async_timeout }}"
poll: 0
when: async
no_log: "{{ not debug_mode }}"
- name: "Async:: provisioning/deprovisioning keypair"
os_keypair:
auth: "{{ auth_var | default(omit) }}"
name: "{{ res_def['res_name'] | default(res_def['name']) }}"
state: "{{ state }}"
wait: "yes"
register: res_def_output_async
async: "{{ async_timeout }}"
poll: 0
when: async
- name: 'Async:: Check on keypair create task'
async_status: jid={{ res_def_output_async.ansible_job_id }}
register: job_result
until: job_result.finished
retries: 30
when: async
- name: "Async:: Generate keyfile "
copy:
content: "{{ job_result['key']['private_key'] }}"
dest: "{{ default_ssh_key_path }}/{{ res_def['res_name'] | default(res_def['name']) }}.key"
when: state=="present" and res_def_output_async is defined and async
no_log: "{{ not debug_mode }}"
- name: "Async:: save the job id"
set_fact:
topology_job_ids: "{{ topology_job_ids + [ res_def_output ] }}"
when: async
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment