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
New file |
| | |
| | | --- |
| | | - 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 |
| | |
| | | |
| | | ################################################################################ |
| | | ################################################################################ |
| | | ############ 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 |
| | | ################################################################################ |
| | | ################################################################################ |
New file |
| | |
| | | = 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" |
| | | ---- |