Skip to content

Commit

Permalink
Ensure we're targeting the right VMs
Browse files Browse the repository at this point in the history
If a user has multiple deployments, they therefore have mutliple blocks
in their `~/.ssh/config`.

While the ssh configuration allows to chose the right VM using the
hypervisor name (for instance controller-0.builder2), the dynamic
inventory built using `ansible.builtin.add_host` doesn't target the
specific host.

With `delegate_to`, it may happen ansible connects to a wrong VM from a
previous deployment that's still running, and the user will face some
really weird situations - for instance, facts being wrongs (this hit the
networking_mapper and the fetched MAC addresses).

With this patch, we now have specific host targeting, and we also get it
in the logs, for example:
```
changed: [builder2 -> controller-0(controller-0.builder2)]
```
  • Loading branch information
cjeanner committed May 23, 2024
1 parent 2b380d8 commit 2cb913e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions roles/libvirt_manager/tasks/manage_vms.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
ansible.builtin.add_host:
name: "{{ vm_ip.nic.host }}"
groups: "{{ (vm_type == 'crc') | ternary('ocp', vm_type) }}s"
ansible_host: "{{ extracted_ip }}"
ansible_host: "{{ vm_ip.nic.host }}.{{ inventory_hostname }}"
ansible_ssh_user: "{{ _cifmw_libvirt_manager_layout.vms[vm_type].admin_user | default(_init_admin_user) }}"
loop: "{{ vm_ips.results }}"
loop_control:
Expand Down Expand Up @@ -173,7 +173,7 @@
cmd: |-
test -d /home/zuul && exit 0;
set -xe -o pipefail;
echo "{{ vm_ip.nic.host }}" | sudo tee /etc/hostname;
echo "{{ vm_ip.nic.host }}.{{ inventory_hostname }}" | sudo tee /etc/hostname;
sudo hostname -F /etc/hostname;
sudo useradd -m -d /home/zuul zuul;
echo "zuul ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/zuul;
Expand Down Expand Up @@ -226,7 +226,7 @@
ansible.builtin.add_host:
name: "{{ vm_ip.nic.host }}"
groups: "{{ (vm_type == 'crc') | ternary('ocp', vm_type) }}s"
ansible_host: "{{ extracted_ip }}"
ansible_host: "{{ vm_ip.nic.host }}.{{ inventory_hostname }}"
ansible_ssh_user: "{{ _cifmw_libvirt_manager_layout.vms[vm_type].admin_user | default('zuul') }}"
loop: "{{ vm_ips.results }}"
loop_control:
Expand Down

0 comments on commit 2cb913e

Please sign in to comment.