From e2bc8f14e58870018e5ca2cf1f8bac7c56aace5e Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Thu, 17 Sep 2020 16:06:04 +0200 Subject: [PATCH] Test setting common configuration options --- .travis.yml | 12 ++++++++--- tests/test_set_common.yml | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 tests/test_set_common.yml diff --git a/.travis.yml b/.travis.yml index e4979cd..9b62945 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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) diff --git a/tests/test_set_common.yml b/tests/test_set_common.yml new file mode 100644 index 0000000..e2fd624 --- /dev/null +++ b/tests/test_set_common.yml @@ -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