From afdd79fb55c3392cbd98321f124ae4dbfe7091eb Mon Sep 17 00:00:00 2001 From: Markus Katharina Brechtel Date: Wed, 11 Oct 2017 22:54:23 +0000 Subject: [PATCH] differnetiate saved and fetched state --- tasks/file.yml | 10 ++++++++++ tasks/main.yml | 7 +++++++ tasks/save.yml | 9 --------- 3 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 tasks/file.yml diff --git a/tasks/file.yml b/tasks/file.yml new file mode 100644 index 0000000..2b02c9e --- /dev/null +++ b/tasks/file.yml @@ -0,0 +1,10 @@ +--- + +- name: write ssh_known_hosts file + local_action: known_hosts + args: + path: "{{ playbook_dir }}/ssh_known_hosts" + name: "{{ item }}" + key: "{{ item }},{{ hostvars[item].ssh_ip }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }}" + with_items: "{{play_hosts}}" + run_once: true diff --git a/tasks/main.yml b/tasks/main.yml index 7c492c4..583e2c0 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -21,6 +21,13 @@ or not ssh_host_key_state == 'configured' - include: save.yml + when: + ssh_host_key_state == 'configured' or + ssh_host_key_state == 'scanned' or + ssh_host_key_state == 'regenerated' or + ssh_host_key_state == 'fetched' + +- include: file.yml when: ssh_host_key_state == 'configured' or ssh_host_key_state == 'scanned' or diff --git a/tasks/save.yml b/tasks/save.yml index bf2badd..353dcaa 100644 --- a/tasks/save.yml +++ b/tasks/save.yml @@ -5,12 +5,3 @@ - name: host_vars file local_action: template src=host_vars.j2 dest=host_vars/{{inventory_hostname}}/ssh_host_key.yml - -- name: write ssh_known_hosts file - local_action: known_hosts - args: - path: "{{ playbook_dir }}/ssh_known_hosts" - name: "{{ item }}" - key: "{{ item }},{{ hostvars[item].ssh_ip }} ssh-ed25519 {{ hostvars[item].ssh_host_key_ed25519_public }}" - with_items: "{{play_hosts}}" - run_once: true