mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 13:50:22 -07:00
Create network_working_with_command_output.rst (#33709)
Move this content to new location prior to intro_networking.rst refactor
This commit is contained in:
parent
145c6f953d
commit
33c7a157ab
2 changed files with 65 additions and 61 deletions
|
@ -157,64 +157,3 @@ Variables are evaulated in the following order, listed from lowest to highest pr
|
||||||
* Provider
|
* Provider
|
||||||
* Task arguments
|
* Task arguments
|
||||||
|
|
||||||
.. _networking_module_conditionals:
|
|
||||||
|
|
||||||
Conditionals in Networking Modules
|
|
||||||
``````````````````````````````````
|
|
||||||
|
|
||||||
Ansible allows you to use conditionals to control the flow of your playbooks. Ansible networking command modules use the following unique conditional statements.
|
|
||||||
|
|
||||||
* eq - Equal
|
|
||||||
* neq - Not equal
|
|
||||||
* gt - Greater than
|
|
||||||
* ge - Greater than or equal
|
|
||||||
* lt - Less than
|
|
||||||
* le - Less than or equal
|
|
||||||
* contains - Object contains specified item
|
|
||||||
|
|
||||||
|
|
||||||
Conditional statements evaluate the results from the commands that are
|
|
||||||
executed remotely on the device. Once the task executes the command
|
|
||||||
set, the waitfor argument can be used to evaluate the results before
|
|
||||||
returning control to the Ansible playbook.
|
|
||||||
|
|
||||||
For example::
|
|
||||||
|
|
||||||
---
|
|
||||||
- name: wait for interface to be admin enabled
|
|
||||||
eos_command:
|
|
||||||
commands:
|
|
||||||
- show interface Ethernet4 | json
|
|
||||||
waitfor:
|
|
||||||
- "result[0].interfaces.Ethernet4.interfaceStatus eq connected"
|
|
||||||
|
|
||||||
In the above example task, the command :code:`show interface Ethernet4 | json`
|
|
||||||
is executed on the remote device and the results are evaluated. If
|
|
||||||
the path
|
|
||||||
:code:`(result[0].interfaces.Ethernet4.interfaceStatus)` is not equal to
|
|
||||||
"connected", then the command is retried. This process continues
|
|
||||||
until either the condition is satisfied or the number of retries has
|
|
||||||
expired (by default, this is 10 retries at 1 second intervals).
|
|
||||||
|
|
||||||
The commands module can also evaluate more than one set of command
|
|
||||||
results in an interface. For instance::
|
|
||||||
|
|
||||||
---
|
|
||||||
- name: wait for interfaces to be admin enabled
|
|
||||||
eos_command:
|
|
||||||
commands:
|
|
||||||
- show interface Ethernet4 | json
|
|
||||||
- show interface Ethernet5 | json
|
|
||||||
waitfor:
|
|
||||||
- "result[0].interfaces.Ethernet4.interfaceStatus eq connected"
|
|
||||||
- "result[1].interfaces.Ethernet4.interfaceStatus eq connected"
|
|
||||||
|
|
||||||
In the above example, two commands are executed on the
|
|
||||||
remote device, and the results are evaluated. By specifying the result
|
|
||||||
index value (0 or 1), the correct result output is checked against the
|
|
||||||
conditional.
|
|
||||||
|
|
||||||
The waitfor argument must always start with result and then the
|
|
||||||
command index in [], where 0 is the first command in the commands list,
|
|
||||||
1 is the second command, 2 is the third and so on.
|
|
||||||
|
|
||||||
|
|
65
docs/docsite/rst/network_working_with_command_output.rst
Normal file
65
docs/docsite/rst/network_working_with_command_output.rst
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
.. _networking_working_with_command_output:
|
||||||
|
|
||||||
|
**********************************************
|
||||||
|
Working with Command Output in Network Modules
|
||||||
|
**********************************************
|
||||||
|
|
||||||
|
Conditionals in Networking Modules
|
||||||
|
===================================
|
||||||
|
|
||||||
|
Ansible allows you to use conditionals to control the flow of your playbooks. Ansible networking command modules use the following unique conditional statements.
|
||||||
|
|
||||||
|
* ``eq`` - Equal
|
||||||
|
* ``neq`` - Not equal
|
||||||
|
* ``gt`` - Greater than
|
||||||
|
* ``ge`` - Greater than or equal
|
||||||
|
* ``lt`` - Less than
|
||||||
|
* ``le`` - Less than or equal
|
||||||
|
* ``contains`` - Object contains specified item
|
||||||
|
|
||||||
|
|
||||||
|
Conditional statements evaluate the results from the commands that are
|
||||||
|
executed remotely on the device. Once the task executes the command
|
||||||
|
set, the ``wait_for`` argument can be used to evaluate the results before
|
||||||
|
returning control to the Ansible playbook.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
---
|
||||||
|
- name: wait for interface to be admin enabled
|
||||||
|
eos_command:
|
||||||
|
commands:
|
||||||
|
- show interface Ethernet4 | json
|
||||||
|
wait_for:
|
||||||
|
- "result[0].interfaces.Ethernet4.interfaceStatus eq connected"
|
||||||
|
|
||||||
|
In the above example task, the command :code:`show interface Ethernet4 | json`
|
||||||
|
is executed on the remote device and the results are evaluated. If
|
||||||
|
the path
|
||||||
|
:code:`(result[0].interfaces.Ethernet4.interfaceStatus)` is not equal to
|
||||||
|
"connected", then the command is retried. This process continues
|
||||||
|
until either the condition is satisfied or the number of retries has
|
||||||
|
expired (by default, this is 10 retries at 1 second intervals).
|
||||||
|
|
||||||
|
The commands module can also evaluate more than one set of command
|
||||||
|
results in an interface. For instance::
|
||||||
|
|
||||||
|
---
|
||||||
|
- name: wait for interfaces to be admin enabled
|
||||||
|
eos_command:
|
||||||
|
commands:
|
||||||
|
- show interface Ethernet4 | json
|
||||||
|
- show interface Ethernet5 | json
|
||||||
|
wait_for:
|
||||||
|
- "result[0].interfaces.Ethernet4.interfaceStatus eq connected"
|
||||||
|
- "result[1].interfaces.Ethernet4.interfaceStatus eq connected"
|
||||||
|
|
||||||
|
In the above example, two commands are executed on the
|
||||||
|
remote device, and the results are evaluated. By specifying the result
|
||||||
|
index value (0 or 1), the correct result output is checked against the
|
||||||
|
conditional.
|
||||||
|
|
||||||
|
The ``wait_for`` argument must always start with result and then the
|
||||||
|
command index in ``[]``, where ``0`` is the first command in the commands list,
|
||||||
|
``1`` is the second command, ``2`` is the third and so on.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue