Test setting common configuration options

This commit is contained in:
Jakub Jelen 2020-09-17 16:06:04 +02:00
parent 9b3e83b853
commit e2bc8f14e5
2 changed files with 52 additions and 3 deletions

View file

@ -14,14 +14,20 @@ install:
- "{ echo '[defaults]'; echo 'roles_path = ../'; echo 'deprecation_warnings=False'; } >> ansible.cfg"
script:
# 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"
# Run the role
# Test 1: Run the role
- "ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/test_default.yml --connection=local --become -v"
# 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'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Test 3: Check we can set arbitrary configuration options
- >
ANSIBLE_FORCE_COLOR=1 ansible-playbook -i tests/inventory tests/test_set_common.yml --connection=local --become -v
&& (echo 'Common variables test: pass' && exit 0)
|| (echo 'Common variables test: fail' && exit 1)

43
tests/test_set_common.yml Normal file
View file

@ -0,0 +1,43 @@
---
- hosts: all
become: true
tasks:
- name: Configure sshd
include_role:
name: ansible-sshd
vars:
sshd:
AcceptEnv: LANG
Banner: /etc/issue
Ciphers: aes256-gcm@openssh.com
Subsystem: "sftp internal-sftp"
- name: Verify the options are correctly set
block:
- meta: flush_handlers
- name: List effective configuration using sshd -T
command: sshd -T
register: runtime
- name: Print current configuration file
command: cat /etc/ssh/sshd_config
register: config
- name: Check the options are effective
# note, the options are in lower-case here
assert:
that:
- "'acceptenv LANG' in runtime.stdout"
- "'banner /etc/issue' in runtime.stdout"
- "'ciphers aes256-gcm@openssh.com' in runtime.stdout"
- "'subsystem sftp internal-sftp' in runtime.stdout"
- name: Check the options are in configuration file
assert:
that:
- "'AcceptEnv LANG' in config.stdout"
- "'Banner /etc/issue' in config.stdout"
- "'Ciphers aes256-gcm@openssh.com' in config.stdout"
- "'Subsystem sftp internal-sftp' in config.stdout"
tags: tests::verify