From 332e367c3cb1e29c222b2af19b9e7136dd2237ba Mon Sep 17 00:00:00 2001 From: NaeiKinDus Date: Thu, 11 Jul 2024 00:00:00 +0000 Subject: [PATCH] feat(provisioner): add variable that contains hostnames and DNS IP of registered provisioners in provisioner_facts --- .../roles/provisioner/tasks/load_facts.yml | 9 +++++++-- inventory/host_vars/geopoiesis/vars.yml | 2 ++ requirements.txt | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 inventory/host_vars/geopoiesis/vars.yml diff --git a/collections/ansible_collections/nullified/infrastructure/roles/provisioner/tasks/load_facts.yml b/collections/ansible_collections/nullified/infrastructure/roles/provisioner/tasks/load_facts.yml index 159f2a1..4d84177 100644 --- a/collections/ansible_collections/nullified/infrastructure/roles/provisioner/tasks/load_facts.yml +++ b/collections/ansible_collections/nullified/infrastructure/roles/provisioner/tasks/load_facts.yml @@ -3,10 +3,15 @@ block: - name: save current provisioner hostname ansible.builtin.set_fact: - provisioner_hostname: '{{ lookup("pipe", "hostname") }}' + provisioner_hostname: '{{ lookup("ansible.builtin.pipe", "hostname") }}' + - name: retrieve hostnames and IP addresses of all provisioners + ansible.builtin.set_fact: + provisioner_controllers_list: + '{{ provisioner_controllers_list | default({}) | combine({hostvars[item]["ansible_host"]: lookup("community.general.dig", hostvars[item]["ansible_host"])}) }}' + loop: '{{ groups["provisioner"] }}' - name: retrieve provisioner inventory facts ansible.builtin.set_fact: - provisioner_facts: '{{ dict(hostvars[provisioner_hostname]) | moreati.jq.jq(JSON_MATCH_QUERY) }}' + provisioner_facts: '{{ dict(hostvars[provisioner_hostname]) | combine({"provisioner_controllers_list": provisioner_controllers_list}) | moreati.jq.jq(JSON_MATCH_QUERY) }}' when: inventory_hostname == ansible_play_hosts_all[0] run_once: true vars: diff --git a/inventory/host_vars/geopoiesis/vars.yml b/inventory/host_vars/geopoiesis/vars.yml new file mode 100644 index 0000000..8d12a3f --- /dev/null +++ b/inventory/host_vars/geopoiesis/vars.yml @@ -0,0 +1,2 @@ +ansible_become_password: "{{ vault_root_pass }}" +ansible_host: "{{ vault_ansible_host }}" diff --git a/requirements.txt b/requirements.txt index d5b9057..90c98c3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,4 @@ pylint==2.17.5 python-vagrant==1.0.0 yamllint==1.32.0 jq==1.7.0 +dnspython==2.6.1