Document and test alternative invocation of role through include_role

This commit is contained in:
Jakub Jelen 2020-09-17 17:26:09 +02:00
parent 1266519c23
commit 2744b2e225
3 changed files with 39 additions and 1 deletions

View file

@ -17,9 +17,12 @@ script:
# Test 0: Check the roles syntax. # Test 0: Check the roles syntax.
- "ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/test_default.yml --syntax-check" - "ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/test_default.yml --syntax-check"
# Test 1: Run the role # Test 1a: Run the role
- "ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/test_default.yml --connection=local --become -v" - "ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/test_default.yml --connection=local --become -v"
# Test 1b: Run the role through include
- "ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/test_default_include.yml --connection=local --become -v"
# Test 2: Run the role/playbook again, checking to make sure it's idempotent. # Test 2: Run the role/playbook again, checking to make sure it's idempotent.
- > - >
ansible-playbook -i tests/inventory tests/test_default.yml --connection=local --become | grep -q 'changed=0.*failed=0' ansible-playbook -i tests/inventory tests/test_default.yml --connection=local --become | grep -q 'changed=0.*failed=0'

View file

@ -206,6 +206,34 @@ Match Group xusers
X11Forwarding yes X11Forwarding yes
``` ```
Since Ansible 2.4, the role can be invoked using `include_role` keyword,
for example:
```yaml
---
- hosts: all
become: true
tasks:
- name: "Configure sshd"
include_role:
name: willshersystems.sshd
vars:
sshd_skip_defaults: true
sshd:
Compression: true
ListenAddress:
- "0.0.0.0"
- "::"
GSSAPIAuthentication: no
Match:
- Condition: "Group user"
GSSAPIAuthentication: yes
sshd_UsePrivilegeSeparation: no
sshd_match:
- Condition: "Group xusers"
X11Forwarding: yes
Template Generation Template Generation
------------------- -------------------

View file

@ -0,0 +1,7 @@
---
- hosts: all
become: true
tasks:
- name: "Configure sshd"
include_role:
name: ansible-sshd