-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ansible local fact management redesign completed
- Loading branch information
Showing
6 changed files
with
65 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1 @@ | ||
--- | ||
- name: Import linux ansible local facts tasks | ||
ansible.builtin.import_tasks: | ||
file: local_facts.yml | ||
when: | ||
- ansible__role_enabled | bool | ||
- ansible__manage_local_facts | bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,65 @@ | ||
--- | ||
- name: Ensure ansible local facts directory exists on host | ||
become: true | ||
ansible.builtin.file: | ||
state: directory | ||
recurse: true | ||
path: "{{ ansible__local_facts_dir }}" | ||
register: ansible__ensure_local_facts_dir | ||
when: | ||
- linux_role_ansible_enabled | bool | ||
- linux_role_ansible_manage_local_facts | bool | ||
- ansible__local_fact_updates | default([]) | length > 0 | ||
|
||
- name: Temporarily assign host local facts to ansible facts | ||
ansible.builtin.set_fact: | ||
__ansible__local_facts: "{{ ansible_local[ansible__local_fact_name] | default({}) }}" | ||
register: ansible__assign_local_facts | ||
when: | ||
- linux_role_ansible_enabled | bool | ||
- linux_role_ansible_manage_local_facts | bool | ||
- ansible__local_fact_updates | default([]) | length > 0 | ||
|
||
- name: Update host local facts | ||
ansible.utils.update_fact: | ||
updates: "{{ local_fact_updates }}" | ||
vars: | ||
update_paths: "{{ ansible__local_fact_updates | map(attribute='path') | | ||
map('regex_replace', '^ansible_local\\.' + ansible__local_fact_name + '\\.|^ansible_local\\.', '') | | ||
map('regex_replace', '^(?!ansible__local_facts\\.)(.*)$', 'ansible__local_facts.\\1') }}" | ||
map('regex_replace', '^(?!__ansible__local_facts\\.)(.*)$', '__ansible__local_facts.\\1') }}" | ||
local_fact_updates: "{{ {'path': update_paths, 'value': (ansible__local_fact_updates | map(attribute='value'))} | | ||
aybarsm.helper.to_list_of_dicts }}" | ||
register: ansible__update_local_facts | ||
notify: "ansible__local_facts_reread" | ||
notify: "ansible__settle_local_facts" | ||
when: | ||
- linux_role_ansible_enabled | bool | ||
- linux_role_ansible_manage_local_facts | bool | ||
- ansible__local_fact_updates | default([]) | length > 0 | ||
|
||
- name: Undefine host local facts in ansible facts | ||
ansible.builtin.set_fact: | ||
__ansible__local_facts: "{{ undef() }}" | ||
register: ansible__undefine_local_facts | ||
when: | ||
- linux_role_ansible_enabled | bool | ||
- linux_role_ansible_manage_local_facts | bool | ||
- ansible__local_fact_updates | default([]) | length > 0 | ||
|
||
- name: Settle local facts on the host if they have been modified | ||
ansible.builtin.meta: 'flush_handlers' | ||
when: | ||
- linux_role_ansible_enabled | bool | ||
- linux_role_ansible_manage_local_facts | bool | ||
- ansible__local_fact_updates | default([]) | length > 0 | ||
|
||
- name: Re-read local facts on the host if they have been modified | ||
ansible.builtin.meta: 'flush_handlers' | ||
- name: Re-read local facts on the host | ||
become: true | ||
ansible.builtin.setup: | ||
filter: ansible_local | ||
register: ansible__reread_local_facts | ||
when: | ||
- linux_role_ansible_enabled | bool | ||
- linux_role_ansible_manage_local_facts | bool | ||
- ansible__local_fact_updates | default([]) | length > 0 | ||
- ansible__settle_local_facts is defined | ||
- ansible__settle_local_facts.changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
{% set facts_ansible_settled = ansible_local[ansible__local_fact_name] | default({}) %} | ||
{% set facts_role_settled = ansible__local_facts | default({}) %} | ||
{% set facts_role_update_settled = ansible__update_local_facts | default({}) %} | ||
{% set list_merge_strategy = ansible__local_fact_list_merge_strategy | default('prepend') %} | ||
{% set final_local_facts = facts_ansible_settled | combine(facts_role_settled, facts_role_update_settled, recursive=true, list_merge=list_merge_strategy) %} | ||
{% set final_local_facts = facts_ansible_settled | combine(facts_role_update_settled, recursive=true, list_merge=list_merge_strategy) %} | ||
{{ final_local_facts | to_nice_json }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters