[BGP] copy /etc/hosts from the undercloud to the test_host

In case of BGP jobs, the test host is different from the undercloud and
it may need to resolve some host names that are defined within the
undercloud's /etc/hosts file

Change-Id: Ib2b6bfbeb498035dd4207bc8a316a2f42c7d3f90
This commit is contained in:
Eduardo Olivares 2022-12-21 12:09:49 +01:00
parent 820de0b9ac
commit 31c08add37
1 changed files with 37 additions and 7 deletions

View File

@ -8,12 +8,42 @@
- name: ensure auto ssh key exchange in test host
block:
- name: Retrieve public key from private key
command: "ssh-keygen -y -f ~/.ssh/id_rsa"
register: test_host_pubkey_result
- name: Retrieve public key from private key
command: "ssh-keygen -y -f ~/.ssh/id_rsa"
register: test_host_pubkey_result
- name: insert the public key to the known test host
authorized_key:
user: "{{ ansible_ssh_user }}"
key: "{{ test_host_pubkey_result.stdout }}"
- name: insert the public key to the known test host
authorized_key:
user: "{{ ansible_ssh_user }}"
key: "{{ test_host_pubkey_result.stdout }}"
ignore_errors: yes
- name: copy /etc/hosts from the undercloud to the test_host
block:
- name: read /etc/hosts from the undercloud
become: true
slurp:
src: /etc/hosts
delegate_to: "{{ groups.undercloud|first }}"
register: hosts_file
- name: write /etc/hosts to the test_host
become: true
copy:
content: "{{ hosts_file.content | b64decode }}"
dest: /etc/hosts
force: true
owner: root
group: root
mode: '0644'
- name: ensure 127.0.0.1 is not in the test_host /etc/hosts file
become: yes
lineinfile:
path: /etc/hosts
regexp: '^127.0.0.1 .*undercloud'
state: absent
ignore_errors: yes
when:
- groups.get("undercloud")
- test_host not in groups.undercloud