Initial commit

This commit is contained in:
Richard Megginson
2024-10-22 10:07:09 -06:00
committed by GitHub
commit e898442752
63 changed files with 2164 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
---
# tasks file for caller
- name: Include role
include_role:
name: "{{ roletoinclude }}"
- name: Assert variable not overridden
assert:
that: not __caller_override
+3
View File
@@ -0,0 +1,3 @@
---
# vars file for caller
__caller_override: false
+1
View File
@@ -0,0 +1 @@
../../../defaults
+1
View File
@@ -0,0 +1 @@
../../../handlers
+1
View File
@@ -0,0 +1 @@
../../../meta
+1
View File
@@ -0,0 +1 @@
../../../tasks
+1
View File
@@ -0,0 +1 @@
../../../templates
+1
View File
@@ -0,0 +1 @@
../../../vars
+14
View File
@@ -0,0 +1,14 @@
---
- name: Setup snapshot
hosts: all
tasks:
- name: Set platform/version specific variables
include_role:
name: linux-system-roles.template
tasks_from: set_vars.yml
public: true
- name: Install test packages
package:
name: "{{ __template_packages }}"
state: present
+16
View File
@@ -0,0 +1,16 @@
# SPDX-License-Identifier: MIT
---
- name: Get file
slurp:
path: "{{ __file }}"
register: __content
when: not __file_content is defined
- name: Check for presence of ansible managed header, fingerprint
assert:
that:
- ansible_managed in content
- __fingerprint in content
vars:
content: "{{ (__file_content | d(__content)).content | b64decode }}"
ansible_managed: "{{ lookup('template', 'get_ansible_managed.j2') }}"
+1
View File
@@ -0,0 +1 @@
{{ ansible_managed | comment(__comment_type | d("plain")) }}
+13
View File
@@ -0,0 +1,13 @@
# SPDX-License-Identifier: MIT
---
- name: Ensure that the role runs with default parameters
hosts: all
gather_facts: false # test that role works in this case
roles:
- linux-system-roles.template
tasks:
- name: Check header for ansible_managed, fingerprint
include_tasks: tasks/check_header.yml
vars:
__file: /etc/foo.conf
__fingerprint: system_role:template
+55
View File
@@ -0,0 +1,55 @@
---
- name: Test role include variable override
hosts: all
gather_facts: true
tasks:
- name: Create var file in caller that can override the one in called role
delegate_to: localhost
copy:
# usually the fake file will cause the called role to crash of
# overriding happens, but if not, set a variable that will
# allow to detect the bug
content: "__caller_override: true"
# XXX ugly, self-modifying code - changes the "caller" role on
# the controller
dest: "{{ playbook_dir }}/roles/caller/vars/{{ item }}.yml"
mode: preserve
loop: "{{ varfiles | unique }}"
# In case the playbook is executed against multiple hosts, use
# only the first one. Otherwise the hosts would stomp on each
# other since they are changing files on the controller.
when: inventory_hostname == ansible_play_hosts_all[0]
vars:
# change to hostvars['localhost']['ansible_facts'] to use the
# information for localhost
facts: "{{ ansible_facts }}"
versions:
- "{{ facts['distribution_version'] }}"
- "{{ facts['distribution_major_version'] }}"
separators: ["-", "_"]
# create all variants like CentOS, CentOS_8.1, CentOS-8.1,
# CentOS-8, CentOS-8.1
# more formally:
# {{ ansible_distribution }}-{{ ansible_distribution_version }}
# {{ ansible_distribution }}-{{ ansible_distribution_major_version }}
# {{ ansible_distribution }}
# {{ ansible_os_family }}
# and the same for _ as separator.
varfiles: "{{ [facts['distribution']] | product(separators) |
map('join') | product(versions) | map('join') | list +
[facts['distribution'], facts['os_family']] }}"
register: __varfiles_created
- name: Import role
import_role:
name: caller
vars:
roletoinclude: linux-system-roles.template
- name: Cleanup
file:
path: "{{ item.dest }}"
state: absent
loop: "{{ __varfiles_created.results }}"
delegate_to: localhost
when: inventory_hostname == ansible_play_hosts_all[0]