|
|
@ -28,7 +28,7 @@ things in your playbooks.
|
|
|
|
.. code-block:: yaml
|
|
|
|
.. code-block:: yaml
|
|
|
|
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
tasks:
|
|
|
|
- service:
|
|
|
|
- ansible.builtin.service:
|
|
|
|
name: foo
|
|
|
|
name: foo
|
|
|
|
state: started
|
|
|
|
state: started
|
|
|
|
enabled: yes
|
|
|
|
enabled: yes
|
|
|
@ -54,7 +54,7 @@ want certain steps to execute in normal mode even when the `--check` flag is use
|
|
|
|
- webserver
|
|
|
|
- webserver
|
|
|
|
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
tasks:
|
|
|
|
- script: verify.sh
|
|
|
|
- ansible.builtin.script: verify.sh
|
|
|
|
check_mode: no
|
|
|
|
check_mode: no
|
|
|
|
|
|
|
|
|
|
|
|
Modules That Are Useful for Testing
|
|
|
|
Modules That Are Useful for Testing
|
|
|
@ -64,7 +64,7 @@ Certain playbook modules are particularly good for testing. Below is an example
|
|
|
|
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
tasks:
|
|
|
|
|
|
|
|
|
|
|
|
- wait_for:
|
|
|
|
- ansible.builtin.wait_for:
|
|
|
|
host: "{{ inventory_hostname }}"
|
|
|
|
host: "{{ inventory_hostname }}"
|
|
|
|
port: 22
|
|
|
|
port: 22
|
|
|
|
delegate_to: localhost
|
|
|
|
delegate_to: localhost
|
|
|
@ -84,8 +84,8 @@ It's easy to push an arbitrary script (in any language) on a remote host and the
|
|
|
|
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
tasks:
|
|
|
|
|
|
|
|
|
|
|
|
- script: test_script1
|
|
|
|
- ansible.builtin.script: test_script1
|
|
|
|
- script: test_script2 --parameter value --parameter2 value
|
|
|
|
- ansible.builtin.script: test_script2 --parameter value --parameter2 value
|
|
|
|
|
|
|
|
|
|
|
|
If using roles (you should be, roles are great!), scripts pushed by the script module can live in the 'files/' directory of a role.
|
|
|
|
If using roles (you should be, roles are great!), scripts pushed by the script module can live in the 'files/' directory of a role.
|
|
|
|
|
|
|
|
|
|
|
@ -93,10 +93,10 @@ And the assert module makes it very easy to validate various kinds of truth::
|
|
|
|
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
tasks:
|
|
|
|
|
|
|
|
|
|
|
|
- shell: /usr/bin/some-command --parameter value
|
|
|
|
- ansible.builtin.shell: /usr/bin/some-command --parameter value
|
|
|
|
register: cmd_result
|
|
|
|
register: cmd_result
|
|
|
|
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
- ansible.builtin.assert:
|
|
|
|
that:
|
|
|
|
that:
|
|
|
|
- "'not ready' not in cmd_result.stderr"
|
|
|
|
- "'not ready' not in cmd_result.stderr"
|
|
|
|
- "'gizmo enabled' in cmd_result.stdout"
|
|
|
|
- "'gizmo enabled' in cmd_result.stdout"
|
|
|
@ -105,11 +105,11 @@ Should you feel the need to test for the existence of files that are not declara
|
|
|
|
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
tasks:
|
|
|
|
|
|
|
|
|
|
|
|
- stat:
|
|
|
|
- ansible.builtin.stat:
|
|
|
|
path: /path/to/something
|
|
|
|
path: /path/to/something
|
|
|
|
register: p
|
|
|
|
register: p
|
|
|
|
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
- ansible.builtin.assert:
|
|
|
|
that:
|
|
|
|
that:
|
|
|
|
- p.stat.exists and p.stat.isdir
|
|
|
|
- p.stat.exists and p.stat.isdir
|
|
|
|
|
|
|
|
|
|
|
@ -157,7 +157,7 @@ This is the great culmination of embedded tests::
|
|
|
|
pre_tasks:
|
|
|
|
pre_tasks:
|
|
|
|
|
|
|
|
|
|
|
|
- name: take out of load balancer pool
|
|
|
|
- name: take out of load balancer pool
|
|
|
|
command: /usr/bin/take_out_of_pool {{ inventory_hostname }}
|
|
|
|
ansible.builtin.command: /usr/bin/take_out_of_pool {{ inventory_hostname }}
|
|
|
|
delegate_to: 127.0.0.1
|
|
|
|
delegate_to: 127.0.0.1
|
|
|
|
|
|
|
|
|
|
|
|
roles:
|
|
|
|
roles:
|
|
|
@ -169,7 +169,7 @@ This is the great culmination of embedded tests::
|
|
|
|
post_tasks:
|
|
|
|
post_tasks:
|
|
|
|
|
|
|
|
|
|
|
|
- name: add back to load balancer pool
|
|
|
|
- name: add back to load balancer pool
|
|
|
|
command: /usr/bin/add_back_to_pool {{ inventory_hostname }}
|
|
|
|
ansible.builtin.command: /usr/bin/add_back_to_pool {{ inventory_hostname }}
|
|
|
|
delegate_to: 127.0.0.1
|
|
|
|
delegate_to: 127.0.0.1
|
|
|
|
|
|
|
|
|
|
|
|
Of course in the above, the "take out of the pool" and "add back" steps would be replaced with a call to an Ansible load balancer
|
|
|
|
Of course in the above, the "take out of the pool" and "add back" steps would be replaced with a call to an Ansible load balancer
|
|
|
@ -192,7 +192,7 @@ This above approach can also be modified to run a step from a testing machine re
|
|
|
|
pre_tasks:
|
|
|
|
pre_tasks:
|
|
|
|
|
|
|
|
|
|
|
|
- name: take out of load balancer pool
|
|
|
|
- name: take out of load balancer pool
|
|
|
|
command: /usr/bin/take_out_of_pool {{ inventory_hostname }}
|
|
|
|
ansible.builtin.command: /usr/bin/take_out_of_pool {{ inventory_hostname }}
|
|
|
|
delegate_to: 127.0.0.1
|
|
|
|
delegate_to: 127.0.0.1
|
|
|
|
|
|
|
|
|
|
|
|
roles:
|
|
|
|
roles:
|
|
|
@ -201,13 +201,13 @@ This above approach can also be modified to run a step from a testing machine re
|
|
|
|
- webserver
|
|
|
|
- webserver
|
|
|
|
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
tasks:
|
|
|
|
- script: /srv/qa_team/app_testing_script.sh --server {{ inventory_hostname }}
|
|
|
|
- ansible.builtin.script: /srv/qa_team/app_testing_script.sh --server {{ inventory_hostname }}
|
|
|
|
delegate_to: testing_server
|
|
|
|
delegate_to: testing_server
|
|
|
|
|
|
|
|
|
|
|
|
post_tasks:
|
|
|
|
post_tasks:
|
|
|
|
|
|
|
|
|
|
|
|
- name: add back to load balancer pool
|
|
|
|
- name: add back to load balancer pool
|
|
|
|
command: /usr/bin/add_back_to_pool {{ inventory_hostname }}
|
|
|
|
ansible.builtin.command: /usr/bin/add_back_to_pool {{ inventory_hostname }}
|
|
|
|
delegate_to: 127.0.0.1
|
|
|
|
delegate_to: 127.0.0.1
|
|
|
|
|
|
|
|
|
|
|
|
In the above example, a script is run from the testing server against a remote node prior to bringing it back into
|
|
|
|
In the above example, a script is run from the testing server against a remote node prior to bringing it back into
|
|
|
|