Guillaume Coré
2018-10-03 a5b75c4bb5a0ed14fadf2726767e4f73927c656f
Enable the use of Ansible Galaxy roles

Allow the use of Galaxy Roles in a config. If a 'requirements.yml' file exist
then automatically install the roles in the configs/{{env_type}}/roles directory.

Create HowTo doc.
2 files added
1 files modified
62 ■■■■■ changed files
ansible/install_galaxy_roles.yml 23 ●●●●● patch | view | raw | blame | history
ansible/main.yml 11 ●●●●● patch | view | raw | blame | history
docs/How_to_use_galaxy_roles_in_your_config.adoc 28 ●●●●● patch | view | raw | blame | history
ansible/install_galaxy_roles.yml
New file
@@ -0,0 +1,23 @@
---
- name: Step 0000 - Install Galaxy roles
  hosts: localhost
  connection: local
  gather_facts: false
  become: false
  vars:
    # User can override this variable to specify a different requirements.yml, like:
    # -e requirements_path=.../requirements_prod.yml
    requirements_path: "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/requirements.yml"
  tasks:
    - name: Check if requirements.yml exists
      stat:
        path: "{{ requirements_path }}"
      register: r_requirements_stat
    - name: Import roles from requirements.yml
      command: >-
        ansible-galaxy install
        -r "{{ requirements_path }}"
        -p "{{ ANSIBLE_REPO_PATH }}/configs/{{ env_type }}/roles"
      when: r_requirements_stat.stat.exists
ansible/main.yml
@@ -3,6 +3,17 @@
################################################################################
################################################################################
############ Step 0000 Pre step Load galaxy roles of the config
################################################################################
################################################################################
- import_playbook: install_galaxy_roles.yml
  tags:
    - step0000
    - galaxy_roles
################################################################################
################################################################################
############ Step 000 Pre Infrastructure Deploy Tasks
################################################################################
################################################################################
docs/How_to_use_galaxy_roles_in_your_config.adoc
New file
@@ -0,0 +1,28 @@
= Galaxy Roles
To use galaxy roles in your config, just do the following:
. Create `requirements.yml` file in the config directory, for example `ansible/configs/myconfig/requirements.yml`.
+
.Example of requirements.yml
[source,yaml]
----
---
- src: geerlingguy.docker
  name: docker
----
. Use the role in the playbooks
+
.pre_software.yml
[source,yaml]
----
- name: Some play
  hosts:
    - myhosts
  become: true
  gather_facts: False
  tasks:
    - name: install docker
      include_role:
        name: "docker"
----