forked from network-automation/toolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconditional_network_demo.yml
69 lines (59 loc) · 1.64 KB
/
conditional_network_demo.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
---
- name: Conditional Network Demo
hosts: cisco
connection: network_cli
gather_facts: no
vars:
ntp_server: "216.239.35.0"
ntp_server_fail: "300.300.300.300"
when_IOS: "IOS"
when_NXOS: "NXOS"
my_param: 50
tasks:
- name: ipv4 success
assert:
that:
- "ntp_server | ipaddr"
success_msg: "'This is a valid IPv4 address"
- name: ipv4 fail
assert:
that:
- "ntp_server_fail | ipaddr"
msg: "This is NOT a valid IPv4 address"
ignore_errors: True
- name: IOS and NXOS
assert:
that:
- when_IOS == "IOS"
- when_NXOS == "NXOS"
success_msg: "This is IOS and NXOS"
- name: IOS or not NXOS
assert:
that:
- when_IOS == "IOS" or when_NXOS != "NXOS"
success_msg: "This is IOS or not NXOS"
- name: fail and success my_param
ansible.builtin.assert:
that:
- my_param <= 100
- my_param >= 0
fail_msg: "'my_param' must be between 0 and 100"
success_msg: "'my_param' is between 0 and 100"
- name: When demo success
debug:
msg: "This is IOS conditional check pass"
when: when_IOS == "IOS"
- name: When demo failure
debug:
msg: "This is IOS conditional check failure"
when: when_IOS != "IOS"
ignore_errors: True
- name: check for IOS in show version
cisco.ios.command:
commands: show version
wait_for: result[0] contains IOS
- name: Using fail module
fail:
msg: This is IOS fail module check failure
when: when_IOS == "IOS"
ignore_errors: True