MikeCaspar.testForCommandResponse
testCommandResponse
===================
testCommandResponse (experimental role)
This role might not be ready for production but it is functional.
It's better to create individual roles for specific tasks, but this role allows you to quickly run system commands if you know how to query settings using the command: for your environment.
Since it uses command:, it should work in any environment that command: supports (though it hasn't been tested in all). If it works for you, please let me know.
This role is meant to be used with the maintain_/test_ loop shown at AnsibleFest 2016 in San Francisco.
test roles are meant to run in read-only mode to check if the test gives a positive or negative result.
If you try this role on another platform, please submit a Pull Request for that platform or feel free to email me to request its addition.
You can read the original slides for the test/maintain loop here.
During this part of the loop, tests are made using a _test.yml file, which can be run separately from _maintain playbooks.
This enables a test-first or parallel testing approach, and _test.yml can also be used as a governance check.
To help those who want to use this method, I’ve decided to share pre-defined example roles for anyone who doesn't want to start from scratch.
The goal is to enable teams working on infrastructure to use existing Ansible YAML syntax without needing to learn Python.
Requirements
You need a working Ansible installation version 1.9 or higher.
Role Variables
- command (string) - Required (commands should not change anything !!)
- expected (string) - Required (the expected string response, using 'contains')
- debug (true/false) - Optional; shows debug information as it runs (defaults to false)
- immediate_exit_on_fail (true/false) - Optional; exits the test playbook immediately on the first failure (defaults to false)
Dependencies
No dependencies.
Example Playbook
Test/confirm that the string "disable monitor" is present in "/etc/ntp.conf" on the system being tested.
# playbook: application1_proxy_test.yml
- hosts: servers
roles:
- { role: MikeCaspar.testCommandResponse, command:"cat /etc/ntp.conf", expected: 'disable monitor' }
License
MIT
Author Information
This role was created in 2016 by Mike Caspar.
Playbook test role for _test/_maintain loop - testCommandResponse
ansible-galaxy install MikeCaspar.testForCommandResponse