Handle host with unset ansible_host

We are having all machines in DNS and want to be able to change IP addresses in DNS. So we do not 
use ansible_host in our host_vars/machine.yml

As os_keystone is the first Ansible role we use. We will make similar changes to other roles later 
on.

Change-Id: Ic9f43cc3f6b62b5098e85afcf55f008c022517f6
This commit is contained in:
Sven Anders 2021-08-10 17:09:03 +02:00 committed by Marc Gariépy
parent 6e84e3a4c7
commit 54a4e496b9
4 changed files with 15 additions and 6 deletions

View File

@ -21,7 +21,7 @@
-avz -avz
--delete --delete
{{ keystone_credential_key_repository }}/ {{ keystone_credential_key_repository }}/
{{ keystone_system_user_name }}@{{ hostvars[item]['ansible_host'] }}:{{ keystone_credential_key_repository }}/ {{ keystone_system_user_name }}@{{ hostvars[item]['ansible_host'] | default(item) }}:{{ keystone_credential_key_repository }}/
become: yes become: yes
become_user: "{{ keystone_system_user_name }}" become_user: "{{ keystone_system_user_name }}"
changed_when: false changed_when: false

View File

@ -21,7 +21,7 @@
-avz -avz
--delete --delete
{{ keystone_fernet_tokens_key_repository }}/ {{ keystone_fernet_tokens_key_repository }}/
{{ keystone_system_user_name }}@{{ hostvars[item]['ansible_host'] }}:{{ keystone_fernet_tokens_key_repository }}/ {{ keystone_system_user_name }}@{{ hostvars[item]['ansible_host'] | default(item) }}:{{ keystone_fernet_tokens_key_repository }}/
become: yes become: yes
become_user: "{{ keystone_system_user_name }}" become_user: "{{ keystone_system_user_name }}"
changed_when: false changed_when: false

View File

@ -40,13 +40,17 @@ function autorotate {
{% for host in groups['keystone_all'] %} {% for host in groups['keystone_all'] %}
{% if inventory_hostname != host %} {% if inventory_hostname != host %}
{% if 'ansible_host' in hostvars[host] %}
{% set destination_host = hostvars[host]['ansible_host'] %}
{% else %}
{% set destination_host = inventory_hostname %}
{% endif %}
# Fernet sync job to "{{ host }}" # Fernet sync job to "{{ host }}"
rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \ rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
-avz \ -avz \
--delete \ --delete \
{{ keystone_credential_key_repository }}/ \ {{ keystone_credential_key_repository }}/ \
{{ keystone_system_user_name }}@{{ hostvars[host]['ansible_host'] }}:{{ keystone_credential_key_repository }}/ {{ keystone_system_user_name }}@{{ destination_host }}:{{ keystone_credential_key_repository }}/
{%- endif %} {%- endif %}

View File

@ -29,18 +29,23 @@ function autorotate {
{% for host in groups['keystone_all'] %} {% for host in groups['keystone_all'] %}
{% if inventory_hostname != host %} {% if inventory_hostname != host %}
{% if 'ansible_host' in hostvars[host] %}
{% set destination_host = hostvars[host]['ansible_host'] %}
{% else %}
{% set destination_host = inventory_hostname %}
{% endif %}
# Fernet sync job to "{{ host }}" # Fernet sync job to "{{ host }}"
scp -o UserKnownHostsFile=/dev/null \ scp -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \ -o StrictHostKeyChecking=no \
$(ls -dtr {{ keystone_fernet_tokens_key_repository }}/* | sort -Vr) \ $(ls -dtr {{ keystone_fernet_tokens_key_repository }}/* | sort -Vr) \
{{ keystone_system_user_name }}@{{ hostvars[host]['ansible_host'] }}:{{ keystone_fernet_tokens_key_repository }}/ {{ keystone_system_user_name }}@{{ destination_host }}:{{ keystone_fernet_tokens_key_repository }}/
rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \ rsync -e 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \
-avz \ -avz \
--delete \ --delete \
{{ keystone_fernet_tokens_key_repository }}/ \ {{ keystone_fernet_tokens_key_repository }}/ \
{{ keystone_system_user_name }}@{{ hostvars[host]['ansible_host'] }}:{{ keystone_fernet_tokens_key_repository }}/ {{ keystone_system_user_name }}@{{ destination_host }}:{{ keystone_fernet_tokens_key_repository }}/
{%- endif %} {%- endif %}