Skip to content

Commit

Permalink
Fix dns check for ipv6 and network connection check for nmstate (redh…
Browse files Browse the repository at this point in the history
…at-partner-solutions#230)

* Allow IPv6 vips in dns check

* Fix network config roll back when vm_host and bastion are the same

---------

Co-authored-by: Michele Costa <[email protected]>
  • Loading branch information
nocturnalastro and nocturnalastro authored Mar 17, 2023
1 parent 751b443 commit 076f0e5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
1 change: 1 addition & 0 deletions roles/apply_nmstate/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vm_host_is_bastion: false
16 changes: 16 additions & 0 deletions roles/apply_nmstate/tasks/check_if_vm_host_is_bastion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
- name: Get bastion machine id
ansible.builtin.slurp:
src: /etc/machine-id
register: bastion_machine_id
delegate_to: bastion
become: false

- name: Get vm_host machine id
ansible.builtin.slurp:
src: /etc/machine-id
register: vmhost_machine_id

- name: Check if VM Host is bridge
ansible.builtin.set_fact:
vm_host_is_bastion: "{{ (bastion_machine_id.content == vmhost_machine_id.content) | bool }}"
21 changes: 17 additions & 4 deletions roles/apply_nmstate/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,36 @@
become: true
block:
- name: Install nmstate
package:
ansible.builtin.package:
name: nmstate
state: present

- name: "Copy rendered_nmstate_yml to {{ vm_nmstate_config_path }}"
copy:
ansible.builtin.copy:
content: "{{ rendered_nmstate_yml }}"
dest: "{{ vm_nmstate_config_path }}"
mode: 0644
# No commit is done to revert the changes if they cause the host to be come unreachable

- name: Check if vm_host is bastion
ansible.builtin.include_tasks:
file: check_if_vm_host_is_bastion.yml

- name: Apply nmstate
shell:
ansible.builtin.shell:
cmd: "nmstatectl apply --no-commit --timeout 120 {{ vm_nmstate_config_path }}"
async: 60
poll: 5

- name: "Check for connection wider network"
ansible.builtin.shell:
cmd: "ping -c 4 -W 1 {{ vm_network_test_ip }}"
when: vm_host_is_bastion | bool
register: connection_test_result
until: connection_test_result is succeeded
retries: 60
delay: 5

- name: Commit changes
shell:
ansible.builtin.shell:
cmd: "nmstatectl commit"
2 changes: 1 addition & 1 deletion roles/validate_dns_records/tasks/check.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- name: Check required domain {item} exists
ansible.builtin.shell:
cmd: "{{ required_binary }} {{ item.value }} +short"
cmd: "{{ required_binary }} {{ item.value }} A {{ item.value }} AAAA +short"
register: res
changed_when: false

Expand Down

0 comments on commit 076f0e5

Please sign in to comment.