-
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.
Local fact management added in ansible role
- Loading branch information
Showing
21 changed files
with
220 additions
and
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
linux_role_ansible_enabled: true | ||
linux_role_ansible_manage_local_facts: true | ||
|
||
linux_ansible_local_fact_template: aybarsm_linux.json.fact.j2 | ||
linux_ansible_local_fact_backup: true | ||
linux_ansible_local_facts_dir: "{{ (not lookup('config', 'DEFAULT_FACT_PATH')) | ternary('/etc/ansible/facts.d', lookup('config', 'DEFAULT_FACT_PATH')) }}" | ||
linux_ansible_local_fact_file: "{{ linux_ansible_local_facts_dir }}/aybarsm_linux.fact" |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
- name: Re-assign host local facts to ansible facts | ||
become: true | ||
ansible.builtin.set_fact: | ||
__linux_ansible_local_facts: "{{ linux_ansible_update_local_facts.__linux_ansible_local_facts }}" | ||
register: linux_ansible_local_facts_reassign | ||
listen: "linux_ansible_local_facts_reassign" | ||
notify: linux_ansible_local_facts_settle | ||
|
||
- name: Settle local facts on host if changed | ||
become: true | ||
ansible.builtin.template: | ||
src: "{{ linux_ansible_local_fact_template }}" | ||
dest: "{{ linux_ansible_local_fact_file }}" | ||
backup: "{{ linux_ansible_local_fact_backup | default(omit) | bool }}" | ||
register: linux_ansible_local_facts_settle | ||
listen: "linux_ansible_local_facts_settle" | ||
notify: linux_ansible_local_facts_reread | ||
when: (ansible_local.aybarsm_linux | b64encode) != (__linux_ansible_local_facts | b64encode) | ||
|
||
- name: Re-read local facts | ||
become: true | ||
ansible.builtin.setup: | ||
filter: ansible_local | ||
register: linux_ansible_local_facts_reread | ||
listen: "linux_ansible_local_facts_reread" |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
allow_duplicates: true |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
- name: Create directory on host for ansible local facts | ||
become: true | ||
ansible.builtin.file: | ||
state: directory | ||
recurse: true | ||
path: "{{ linux_ansible_local_facts_dir }}" | ||
|
||
- name: Assign local facts as ansible facts | ||
ansible.builtin.set_fact: | ||
__linux_ansible_local_facts: "{{ ansible_local.aybarsm_linux | default({}) }}" |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
- name: Import linux ansible local facts tasks | ||
ansible.builtin.import_tasks: | ||
file: local_facts.yml | ||
when: | ||
- linux_role_ansible_enabled | bool | ||
- linux_role_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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
--- | ||
- name: Update host local facts | ||
ansible.utils.update_fact: | ||
updates: "{{ host_fact_updates }}" | ||
vars: | ||
fact_basename: "{{ linux_ansible_local_fact_file | basename | regex_replace('\\.fact$', '') }}" | ||
host_fact_updates: "{{ dict(( | ||
ansible_host_fact_updates | map(attribute='path') | | ||
map('regex_replace', '^ansible_local\\.' + fact_basename + '\\.|^ansible_local\\.', '') | | ||
map('regex_replace', '^(?!__linux_ansible_local_facts\\.)(.*)$', '__linux_ansible_local_facts.\\1')) | | ||
zip(ansible_host_fact_updates | map(attribute='value'))) | | ||
dict2items(key_name='path', value_name='value') }}" | ||
register: linux_ansible_update_local_facts | ||
|
||
- name: Re-assign host local facts to ansible facts | ||
ansible.builtin.set_fact: | ||
__linux_ansible_local_facts: "{{ linux_ansible_update_local_facts.__linux_ansible_local_facts }}" | ||
register: linux_ansible_local_facts_reassign | ||
|
||
- name: Settle local facts on host if changed | ||
become: true | ||
ansible.builtin.template: | ||
src: "{{ linux_ansible_local_fact_template }}" | ||
dest: "{{ linux_ansible_local_fact_file }}" | ||
backup: "{{ linux_ansible_local_fact_backup | default(omit) | bool }}" | ||
register: linux_ansible_local_facts_settle | ||
vars: | ||
fact_basename: "{{ linux_ansible_local_fact_file | basename | regex_replace('\\.fact$', '') }}" | ||
on_host: "{{ ansible_local[fact_basename] | default({}) | b64encode }}" | ||
on_runtime: "{{ __linux_ansible_local_facts | default({}) | b64encode }}" | ||
when: on_host != on_runtime | ||
|
||
- name: Re-read local facts | ||
become: true | ||
ansible.builtin.setup: | ||
filter: ansible_local | ||
register: linux_ansible_local_facts_reread | ||
when: linux_ansible_local_facts_settle.changed | ||
|
||
# - name: Settle local facts if they have been modified | ||
# ansible.builtin.meta: 'flush_handlers' |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% if __linux_ansible_local_facts is defined %} | ||
{{ __linux_ansible_local_facts | to_nice_json }} | ||
{% else %} | ||
{ | ||
} | ||
{% endif %} |
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 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 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
- name: Create temporary etc_apt directory | ||
become: true | ||
ansible.builtin.tempfile: | ||
state: directory | ||
suffix: etc_apt | ||
register: linux_package_manager_temp_etc_apt_dir | ||
|
||
- name: Create sources.list.d directory in temporary etc_apt directory | ||
become: true | ||
ansible.builtin.file: | ||
state: directory | ||
recurse: true | ||
path: "{{ linux_package_manager_temp_etc_apt_dir.path }}/sources.list.d" | ||
register: linux_package_manager_temp_etc_apt_sources_dir | ||
|
||
- name: Check main sources.list file status | ||
become: true | ||
ansible.builtin.stat: | ||
path: "{{ linux_package_manager_repo_list_file }}" | ||
register: linux_package_manager_repo_list_file_stat | ||
|
||
# - name: Find apt source files | ||
# become: true | ||
# ansible.builtin.find: | ||
# paths: "{{ linux_systemd_network_dir }}" | ||
# patterns: "{{ linux_systemd_network_cleanup_patterns }}" | ||
# use_regex: "{{ linux_systemd_network_cleanup_patterns_use_regex | bool }}" | ||
# when: linux_systemd_network_cleanup | bool | ||
# register: linux_systemd_network_find_cleanup_files | ||
|
||
# - name: Find apt source files | ||
# become: true | ||
# ansible.builtin.find: | ||
# paths: "{{ linux_systemd_network_dir }}" | ||
# patterns: "{{ linux_systemd_network_cleanup_patterns }}" | ||
# use_regex: "{{ linux_systemd_network_cleanup_patterns_use_regex | bool }}" | ||
# when: linux_systemd_network_cleanup | bool | ||
# register: linux_systemd_network_find_cleanup_files |
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.
Empty file.
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 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
27 changes: 27 additions & 0 deletions
27
roles/package_manager/templates/etc/apt/default.sources.list.j2
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{% set os_distrib = ansible_distribution | lower %} | ||
{% set os_release = ansible_distribution_release | lower %} | ||
{% if os_distrib == "debian" %} | ||
deb http://deb.debian.org/debian/ {{ os_release }} main | ||
deb-src http://deb.debian.org/debian/ {{ os_release }} main | ||
|
||
deb http://security.debian.org/debian-security {{ os_release }}-security main | ||
deb-src http://security.debian.org/debian-security {{ os_release }}-security main | ||
|
||
deb http://deb.debian.org/debian/ {{ os_release }}-updates main | ||
deb-src http://deb.debian.org/debian/ {{ os_release }}-updates main | ||
{% elif os_distrib == "ubuntu" %} | ||
deb http://archive.ubuntu.com/ubuntu/ {{ os_release }} main restricted universe multiverse | ||
deb-src http://archive.ubuntu.com/ubuntu/ {{ os_release }} main restricted universe multiverse | ||
|
||
deb http://archive.ubuntu.com/ubuntu/ {{ os_release }}-updates main restricted universe multiverse | ||
deb-src http://archive.ubuntu.com/ubuntu/ {{ os_release }}-updates main restricted universe multiverse | ||
|
||
deb http://archive.ubuntu.com/ubuntu/ {{ os_release }}-security main restricted universe multiverse | ||
deb-src http://archive.ubuntu.com/ubuntu/ {{ os_release }}-security main restricted universe multiverse | ||
|
||
deb http://archive.ubuntu.com/ubuntu/ {{ os_release }}-backports main restricted universe multiverse | ||
deb-src http://archive.ubuntu.com/ubuntu/ {{ os_release }}-backports main restricted universe multiverse | ||
|
||
deb http://archive.canonical.com/ubuntu {{ os_release }} partner | ||
deb-src http://archive.canonical.com/ubuntu {{ os_release }} partner | ||
{% endif %} |
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 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 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 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,4 +1,13 @@ | ||
--- | ||
- name: Import aybarsm linux ansible role | ||
ansible.builtin.import_role: | ||
name: aybarsm.linux.ansible | ||
|
||
- name: Include Debug Tasks | ||
ansible.builtin.import_tasks: | ||
file: debug.yml | ||
|
||
- name: Import aybarsm linux ansible role - settle local fact tasks | ||
ansible.builtin.import_role: | ||
name: aybarsm.linux.ansible | ||
tasks_from: settle_local_facts.yml |
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