Ensure that we only scan new host keys when we have built a new VM
parent
63a5754b65
commit
a64917859d
@ -1,36 +1,37 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- name: Connect - Ensure we don't have an incorrect SSH host key stored on the Ansible controller
|
- name: Managing SSH Host Keys
|
||||||
ansible.builtin.command:
|
when: create_vm_proxmox_clone_vm is changed
|
||||||
cmd: "ssh-keygen -R {{ ansible_host }}"
|
block:
|
||||||
register: create_vm_proxmox_remove_ssh_host_key_cmd
|
- name: Connect - Remove any existing host keys for this host
|
||||||
changed_when:
|
ansible.builtin.command:
|
||||||
- '"# Host " + ansible_host + " found" in create_vm_proxmox_remove_ssh_host_key_cmd.stdout'
|
cmd: "ssh-keygen -R {{ ansible_host }}"
|
||||||
when:
|
register: create_vm_proxmox_remove_ssh_host_key_cmd
|
||||||
- create_vm_proxmox_remove_ssh_host_key | bool
|
changed_when: '"# Host " + ansible_host + " found" in create_vm_proxmox_remove_ssh_host_key_cmd.stdout'
|
||||||
delegate_to: localhost
|
when: create_vm_proxmox_remove_ssh_host_key | bool
|
||||||
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Connect - Wait for SSH to become available
|
- name: Connect - Wait for SSH to become available
|
||||||
ansible.builtin.wait_for:
|
ansible.builtin.wait_for:
|
||||||
host: "{{ ansible_host }}"
|
host: "{{ ansible_host }}"
|
||||||
port: 22
|
port: 22
|
||||||
delay: 10
|
delay: 10
|
||||||
timeout: 120
|
timeout: 120
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Connect - Get SSH host keys
|
- name: Connect - Get SSH host keys
|
||||||
ansible.builtin.shell:
|
ansible.builtin.shell:
|
||||||
cmd: "ssh-keyscan {{ ansible_host }} >> ~/.ssh/known_hosts"
|
cmd: "ssh-keyscan {{ ansible_host }} >> ~/.ssh/known_hosts"
|
||||||
args:
|
args:
|
||||||
executable: /bin/bash
|
executable: /bin/bash
|
||||||
changed_when: true
|
changed_when: true
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Connect - Ensure we can connect
|
- name: Connect - Ensure we can connect
|
||||||
ansible.builtin.wait_for_connection:
|
ansible.builtin.wait_for_connection:
|
||||||
connect_timeout: 10
|
connect_timeout: 10
|
||||||
delay: 5
|
delay: 5
|
||||||
sleep: 2
|
sleep: 2
|
||||||
timeout: 120
|
timeout: 120
|
||||||
|
|
||||||
...
|
...
|
||||||
|
|||||||
Loading…
Reference in New Issue