A collection of things I commonly use with infrastructure.
Warning
MASSIVE WIP! First collection, just playing around. This is not published to Galaxy.
Note
Again, reminder that I'm just collecting things I use in a generic fashion so that I can use them again in the future. I know it looks strange other wise.
Playbook | Description | Variables |
---|---|---|
hdub_tech.infrastructure.configure_apache2.yml |
Uses hdub_tech.infrastructure.apache2_configure role to modify apache configs and restart the service | Refer to apache2_configure role README |
hdub_tech.infrastructure.configure_swap.yml |
Uses geerlingguy.swap role to enable or disable swap on a linux host | Refer to geerlingguy.swap#role-variables |
Role | Description | Variables |
---|---|---|
hdub_tech.infrastructure.apache2_configure | Uses ansible.builtin.lineinfile module to modify apache configs and restart the service |
Refer to apache2_configure role README |
-
Add this collection to your project by adding it to YOUR project's
ansible-requirements.yml
:collections: - name: [email protected]:hdub-tech/ansible-collection-infrastructure.git type: git version: 1.1.0
-
Install the
hdub_tech.infrastructure
collection:# From YOUR project / venv ansible-galaxy install -r ansible-requirements.yml
-
Install the
hdub_tech.infrastructure
collection's roles dependencies (NOTE: This is necessary because Ansible does not support installing a collection's roles when the collection itself is installed. See ansible#76030)# From YOUR project / venv, if your collections_path is in your project directory: ansible-galaxy install -r collections/ansible_collections/hdub_tech/infrastructure/ansible-requirements.yml
# If it is elsewhere, like ~/.ansible/collections enter that path in lieu of $ANSIBLE_COLLECTIONS_PATH ansible-galaxy install -r $ANSIBLE_COLLECTIONS_PATH/collections/ansible_collections/hdub_tech/infrastructure/ansible-requirements.yml
-
Use a collection playbook by providing the entire
namespace.collectionname.playbookname
(The following usesconfigure_swap.yml
as an example; substitute as necessary):a. To execute a playbook directly:
ansible-playbook -i PATH_TO_YOUR_INVENTORY hdub_tech.infrastructure.configure_swap.yml [--check]
b. To execute a playbook using
ansible-navigator
:ansible-navigator run hdub_tech.infrastructure.configure_swap.yml -i PATH_TO_YOUR_INVENTORY [--check]
c. To use a collection playbook in your playbook:
- name: Configure swap ansible.builtin.import_playbook: hdub_tech.infrastructure.configure_swap
Tip
The lack of .yml
on the import_playbook
line is intentional! If you
include the extension, ansible-lint
(or more specifically the underlying
ansible-playbook --syntax-check
) will report ERROR Failed to find playbook
Most Ansible import_playbook
documentation examples show this, but do
not explicitly state this fact.
-
Use a collection role by providing the entire
namespace.collectionname.rolename
:- hosts: webservers roles: - hdub_tech.infrastructure.ROLENAME vars: ROLENAME_VARNAME: VARVALUE