feat: base configuration automation
This commit is contained in:
commit
e4770a7343
70 changed files with 2489 additions and 0 deletions
|
@ -0,0 +1,9 @@
|
|||
[defaults]
|
||||
# target root path of the repository
|
||||
home = ../../../../..
|
||||
remote_tmp = /tmp
|
||||
local_tmp = /tmp
|
||||
|
||||
[privilege_escalation]
|
||||
become_method = su
|
||||
become_flags = "-l"
|
|
@ -0,0 +1,39 @@
|
|||
---
|
||||
# playbook file that contains the call for your role
|
||||
- name: Fail if molecule group is missing
|
||||
hosts: localhost
|
||||
tasks:
|
||||
- name: Print some info
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ groups }}"
|
||||
|
||||
- name: Assert group existence
|
||||
ansible.builtin.assert:
|
||||
that: "'molecule' in groups"
|
||||
fail_msg: |
|
||||
molecule group was not found inside inventory groups: {{ groups }}
|
||||
|
||||
- name: Converge
|
||||
hosts: molecule
|
||||
gather_facts: true
|
||||
tasks:
|
||||
- name: Testing common role
|
||||
ansible.builtin.include_role:
|
||||
name: nullified.infrastructure.common
|
||||
tasks_from: main.yml
|
||||
- name: Testing development role
|
||||
ansible.builtin.include_role:
|
||||
name: nullified.infrastructure.development
|
||||
tasks_from: main.yml
|
||||
- name: Testing security role
|
||||
ansible.builtin.include_role:
|
||||
name: nullified.infrastructure.security
|
||||
tasks_from: main.yml
|
||||
- name: Testing server role
|
||||
ansible.builtin.include_role:
|
||||
name: nullified.infrastructure.server
|
||||
tasks_from: main.yml
|
||||
- name: Testing workstation role
|
||||
ansible.builtin.include_role:
|
||||
name: nullified.infrastructure.workstation
|
||||
tasks_from: main.yml
|
|
@ -0,0 +1,90 @@
|
|||
---
|
||||
# playbook file used for creating the instances and storing data in instance-config
|
||||
- name: Create
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
vars:
|
||||
molecule_inventory:
|
||||
all:
|
||||
hosts: {}
|
||||
molecule: {}
|
||||
tasks:
|
||||
- name: Create a container
|
||||
community.docker.docker_container:
|
||||
name: "{{ item.name }}"
|
||||
image: "{{ item.image }}"
|
||||
detach: true
|
||||
state: started
|
||||
log_driver: json-file
|
||||
cgroupns_mode: private
|
||||
cgroup_parent: docker.slice
|
||||
mounts:
|
||||
- target: /run
|
||||
type: tmpfs
|
||||
- target: /run/lock
|
||||
type: tmpfs
|
||||
- target: /tmp
|
||||
type: tmpfs
|
||||
register: result
|
||||
loop: "{{ molecule_yml.platforms }}"
|
||||
|
||||
- name: Print some info
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ result.results }}"
|
||||
|
||||
- name: Fail if container is not running
|
||||
when: >
|
||||
item.container.State.ExitCode != 0 or
|
||||
not item.container.State.Running
|
||||
ansible.builtin.include_tasks:
|
||||
file: tasks/create-fail.yml
|
||||
loop: "{{ result.results }}"
|
||||
loop_control:
|
||||
label: "{{ item.container.Name }}"
|
||||
|
||||
- name: Add container to molecule_inventory
|
||||
vars:
|
||||
inventory_partial_yaml: |
|
||||
all:
|
||||
children:
|
||||
molecule:
|
||||
hosts:
|
||||
"{{ item.name }}":
|
||||
ansible_connection: community.docker.docker
|
||||
ansible.builtin.set_fact:
|
||||
molecule_inventory: >
|
||||
{{ molecule_inventory | combine(inventory_partial_yaml | from_yaml) }}
|
||||
loop: "{{ molecule_yml.platforms }}"
|
||||
loop_control:
|
||||
label: "{{ item.name }}"
|
||||
|
||||
- name: Dump molecule_inventory
|
||||
ansible.builtin.copy:
|
||||
content: |
|
||||
{{ molecule_inventory | to_yaml }}
|
||||
dest: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
|
||||
mode: 0600
|
||||
|
||||
- name: Force inventory refresh
|
||||
ansible.builtin.meta: refresh_inventory
|
||||
|
||||
- name: Fail if molecule group is missing
|
||||
ansible.builtin.assert:
|
||||
that: "'molecule' in groups"
|
||||
fail_msg: |
|
||||
molecule group was not found inside inventory groups: {{ groups }}
|
||||
run_once: true # noqa: run-once[task]
|
||||
|
||||
# we want to avoid errors like "Failed to create temporary directory"
|
||||
- name: Validate that inventory was refreshed
|
||||
hosts: molecule
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Check uname
|
||||
ansible.builtin.raw: uname -a
|
||||
register: result
|
||||
changed_when: false
|
||||
|
||||
- name: Display uname info
|
||||
ansible.builtin.debug:
|
||||
msg: "{{ result.stdout }}"
|
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
# destroying the instances and removing them from instance-config
|
||||
- name: Destroy molecule containers
|
||||
hosts: molecule
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Stop and remove container
|
||||
delegate_to: localhost
|
||||
community.docker.docker_container:
|
||||
name: "{{ inventory_hostname }}"
|
||||
state: absent
|
||||
auto_remove: true
|
||||
|
||||
- name: Remove dynamic molecule inventory
|
||||
hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- name: Remove dynamic inventory file
|
||||
ansible.builtin.file:
|
||||
path: "{{ molecule_ephemeral_directory }}/inventory/molecule_inventory.yml"
|
||||
state: absent
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
# central configuration entry point for Molecule per scenario
|
||||
dependency:
|
||||
name: galaxy
|
||||
options:
|
||||
requirements-file: requirements.yml
|
||||
platforms:
|
||||
- name: debian-bookworm
|
||||
image: pouncetech/molecule:debian-bookworm
|
|
@ -0,0 +1,2 @@
|
|||
collections:
|
||||
- community.docker
|
|
@ -0,0 +1,13 @@
|
|||
- name: Retrieve container log
|
||||
ansible.builtin.command:
|
||||
cmd: >-
|
||||
{% raw %}
|
||||
docker logs
|
||||
{% endraw %}
|
||||
{{ item.stdout_lines[0] }}
|
||||
changed_when: false
|
||||
register: logfile_cmd
|
||||
|
||||
- name: Display container log
|
||||
ansible.builtin.fail:
|
||||
msg: "{{ logfile_cmd.stderr }}"
|
Loading…
Add table
Add a link
Reference in a new issue