| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
- name: Test that we have an ACI APIC host, ACI username and ACI password |
| 8 |
ansible.builtin.fail: |
| 9 |
msg: 'Please define the following variables: aci_hostname, aci_username and aci_password.' |
| 10 |
when: aci_hostname is not defined or aci_username is not defined or aci_password is not defined |
| 11 |
|
| 12 |
- name: Set vars |
| 13 |
ansible.builtin.set_fact: |
| 14 |
aci_info: &aci_info |
| 15 |
host: "{{ aci_hostname }}" |
| 16 |
username: "{{ aci_username }}" |
| 17 |
password: "{{ aci_password }}" |
| 18 |
validate_certs: '{{ aci_validate_certs | default(false) }}' |
| 19 |
use_ssl: '{{ aci_use_ssl | default(true) }}' |
| 20 |
use_proxy: '{{ aci_use_proxy | default(true) }}' |
| 21 |
output_level: '{{ aci_output_level | default("info") }}' |
| 22 |
|
| 23 |
|
| 24 |
- name: Remove any pre-existing NTP policy |
| 25 |
cisco.aci.aci_ntp_policy: &policy_absent |
| 26 |
<<: *aci_info |
| 27 |
name: ansible_ntp_policy |
| 28 |
state: absent |
| 29 |
|
| 30 |
|
| 31 |
- name: Add NTP policy (check_mode) |
| 32 |
cisco.aci.aci_ntp_policy: &policy_present |
| 33 |
<<: *aci_info |
| 34 |
name: ansible_ntp_policy |
| 35 |
description: 'Ansible test policy' |
| 36 |
admin_state: enabled |
| 37 |
server_state: disabled |
| 38 |
auth_state: disabled |
| 39 |
state: present |
| 40 |
check_mode: true |
| 41 |
register: cm_add_policy |
| 42 |
|
| 43 |
- name: Add NTP policy (normal mode) |
| 44 |
cisco.aci.aci_ntp_policy: |
| 45 |
<<: *policy_present |
| 46 |
register: nm_add_policy |
| 47 |
|
| 48 |
- name: Add NTP policy again (check mode) |
| 49 |
cisco.aci.aci_ntp_policy: |
| 50 |
<<: *policy_present |
| 51 |
check_mode: true |
| 52 |
register: cm_add_policy_again |
| 53 |
|
| 54 |
- name: Add NTP policy again (normal mode) |
| 55 |
cisco.aci.aci_ntp_policy: |
| 56 |
<<: *policy_present |
| 57 |
register: nm_add_policy_again |
| 58 |
|
| 59 |
- name: Verify add policy |
| 60 |
ansible.builtin.assert: |
| 61 |
that: |
| 62 |
- cm_add_policy is changed |
| 63 |
- nm_add_policy is changed |
| 64 |
- nm_add_policy.current.0.datetimePol.attributes.dn == 'uni/fabric/time-ansible_ntp_policy' |
| 65 |
- nm_add_policy.current.0.datetimePol.attributes.name == 'ansible_ntp_policy' |
| 66 |
- nm_add_policy.current.0.datetimePol.attributes.descr == 'Ansible test policy' |
| 67 |
- nm_add_policy.current.0.datetimePol.attributes.adminSt == 'enabled' |
| 68 |
- nm_add_policy.current.0.datetimePol.attributes.serverState == 'disabled' |
| 69 |
- nm_add_policy.current.0.datetimePol.attributes.authSt == 'disabled' |
| 70 |
- nm_add_policy.current.0.datetimePol.attributes.StratumValue == '8' |
| 71 |
- cm_add_policy_again is not changed |
| 72 |
- nm_add_policy_again is not changed |
| 73 |
- nm_add_policy_again.current.0.datetimePol.attributes.dn == 'uni/fabric/time-ansible_ntp_policy' |
| 74 |
- nm_add_policy_again.current.0.datetimePol.attributes.name == 'ansible_ntp_policy' |
| 75 |
- nm_add_policy_again.current.0.datetimePol.attributes.descr == 'Ansible test policy' |
| 76 |
- nm_add_policy_again.current.0.datetimePol.attributes.adminSt == 'enabled' |
| 77 |
- nm_add_policy_again.current.0.datetimePol.attributes.serverState == 'disabled' |
| 78 |
- nm_add_policy_again.current.0.datetimePol.attributes.authSt == 'disabled' |
| 79 |
- nm_add_policy_again.current.0.datetimePol.attributes.StratumValue == '8' |
| 80 |
|
| 81 |
|
| 82 |
- name: Modify policy (check_mode) |
| 83 |
cisco.aci.aci_ntp_policy: &policy_changed |
| 84 |
<<: *aci_info |
| 85 |
name: ansible_ntp_policy |
| 86 |
description: 'Ansible updated test policy' |
| 87 |
admin_state: enabled |
| 88 |
server_state: enabled |
| 89 |
auth_state: disabled |
| 90 |
stratum: 9 |
| 91 |
state: present |
| 92 |
check_mode: true |
| 93 |
register: cm_modify_policy |
| 94 |
|
| 95 |
- name: Modify policy (normal mode) |
| 96 |
cisco.aci.aci_ntp_policy: |
| 97 |
<<: *policy_changed |
| 98 |
register: nm_modify_policy |
| 99 |
|
| 100 |
- name: Modify policy again (check mode) |
| 101 |
cisco.aci.aci_ntp_policy: |
| 102 |
<<: *policy_changed |
| 103 |
check_mode: true |
| 104 |
register: cm_modify_policy_again |
| 105 |
|
| 106 |
- name: Modify policy again (normal mode) |
| 107 |
cisco.aci.aci_ntp_policy: |
| 108 |
<<: *policy_changed |
| 109 |
register: nm_modify_policy_again |
| 110 |
|
| 111 |
- name: Verify modify policy |
| 112 |
ansible.builtin.assert: |
| 113 |
that: |
| 114 |
- cm_modify_policy is changed |
| 115 |
- nm_modify_policy is changed |
| 116 |
- nm_modify_policy.current.0.datetimePol.attributes.dn == 'uni/fabric/time-ansible_ntp_policy' |
| 117 |
- nm_modify_policy.current.0.datetimePol.attributes.name == 'ansible_ntp_policy' |
| 118 |
- nm_modify_policy.current.0.datetimePol.attributes.descr == 'Ansible updated test policy' |
| 119 |
- nm_modify_policy.current.0.datetimePol.attributes.adminSt == 'enabled' |
| 120 |
- nm_modify_policy.current.0.datetimePol.attributes.serverState == 'enabled' |
| 121 |
- nm_modify_policy.current.0.datetimePol.attributes.authSt == 'disabled' |
| 122 |
- nm_modify_policy.current.0.datetimePol.attributes.StratumValue == '9' |
| 123 |
- cm_modify_policy_again is not changed |
| 124 |
- nm_modify_policy_again is not changed |
| 125 |
- nm_modify_policy_again.current.0.datetimePol.attributes.dn == 'uni/fabric/time-ansible_ntp_policy' |
| 126 |
- nm_modify_policy_again.current.0.datetimePol.attributes.name == 'ansible_ntp_policy' |
| 127 |
- nm_modify_policy_again.current.0.datetimePol.attributes.descr == 'Ansible updated test policy' |
| 128 |
- nm_modify_policy_again.current.0.datetimePol.attributes.adminSt == 'enabled' |
| 129 |
- nm_modify_policy_again.current.0.datetimePol.attributes.serverState == 'enabled' |
| 130 |
- nm_modify_policy_again.current.0.datetimePol.attributes.authSt == 'disabled' |
| 131 |
- nm_modify_policy_again.current.0.datetimePol.attributes.StratumValue == '9' |
| 132 |
|
| 133 |
|
| 134 |
- name: Query all policies (check_mode) |
| 135 |
cisco.aci.aci_ntp_policy: &policy_query_all |
| 136 |
<<: *aci_info |
| 137 |
state: query |
| 138 |
check_mode: true |
| 139 |
register: cm_query_all_policies |
| 140 |
|
| 141 |
- name: Query all policies (normal mode) |
| 142 |
cisco.aci.aci_ntp_policy: |
| 143 |
<<: *policy_query_all |
| 144 |
register: nm_query_all_policies |
| 145 |
|
| 146 |
- name: Verify query_all_policies |
| 147 |
ansible.builtin.assert: |
| 148 |
that: |
| 149 |
- cm_query_all_policies is not changed |
| 150 |
- nm_query_all_policies is not changed |
| 151 |
|
| 152 |
|
| 153 |
- name: Query our policy (check_mode) |
| 154 |
cisco.aci.aci_ntp_policy: |
| 155 |
<<: *policy_query_all |
| 156 |
name: ansible_ntp_policy |
| 157 |
check_mode: true |
| 158 |
register: cm_query_policy |
| 159 |
|
| 160 |
- name: Query our policy (normal mode) |
| 161 |
cisco.aci.aci_ntp_policy: |
| 162 |
<<: *policy_query_all |
| 163 |
name: ansible_ntp_policy |
| 164 |
register: nm_query_policy |
| 165 |
|
| 166 |
- name: Verify query_policy |
| 167 |
ansible.builtin.assert: |
| 168 |
that: |
| 169 |
- cm_query_policy is not changed |
| 170 |
- nm_query_policy is not changed |
| 171 |
- cm_query_policy == nm_query_policy |
| 172 |
- nm_query_policy.current.0.datetimePol.attributes.dn == 'uni/fabric/time-ansible_ntp_policy' |
| 173 |
- nm_query_policy.current.0.datetimePol.attributes.name == 'ansible_ntp_policy' |
| 174 |
- nm_query_policy.current.0.datetimePol.attributes.descr == 'Ansible updated test policy' |
| 175 |
- nm_query_policy.current.0.datetimePol.attributes.adminSt == 'enabled' |
| 176 |
- nm_query_policy.current.0.datetimePol.attributes.serverState == 'enabled' |
| 177 |
- nm_query_policy.current.0.datetimePol.attributes.authSt == 'disabled' |
| 178 |
- nm_query_policy.current.0.datetimePol.attributes.StratumValue == '9' |
| 179 |
|
| 180 |
|
| 181 |
- name: Remove policy (check_mode) |
| 182 |
cisco.aci.aci_ntp_policy: |
| 183 |
<<: *policy_absent |
| 184 |
check_mode: true |
| 185 |
register: cm_remove_policy |
| 186 |
|
| 187 |
- name: Remove policy (normal mode) |
| 188 |
cisco.aci.aci_ntp_policy: |
| 189 |
<<: *policy_absent |
| 190 |
register: nm_remove_policy |
| 191 |
|
| 192 |
- name: Remove policy again (check_mode) |
| 193 |
cisco.aci.aci_ntp_policy: |
| 194 |
<<: *policy_absent |
| 195 |
check_mode: true |
| 196 |
register: cm_remove_policy_again |
| 197 |
|
| 198 |
- name: Remove policy again (normal mode) |
| 199 |
cisco.aci.aci_ntp_policy: |
| 200 |
<<: *policy_absent |
| 201 |
register: nm_remove_policy_again |
| 202 |
|
| 203 |
- name: Verify remove_policy |
| 204 |
ansible.builtin.assert: |
| 205 |
that: |
| 206 |
- cm_remove_policy is changed |
| 207 |
- nm_remove_policy is changed |
| 208 |
- nm_remove_policy.current == [] |
| 209 |
- nm_remove_policy.previous.0.datetimePol.attributes.dn == 'uni/fabric/time-ansible_ntp_policy' |
| 210 |
- nm_remove_policy.previous.0.datetimePol.attributes.name == 'ansible_ntp_policy' |
| 211 |
- nm_remove_policy.previous.0.datetimePol.attributes.descr == 'Ansible updated test policy' |
| 212 |
- nm_remove_policy.previous.0.datetimePol.attributes.adminSt == 'enabled' |
| 213 |
- nm_remove_policy.previous.0.datetimePol.attributes.serverState == 'enabled' |
| 214 |
- nm_remove_policy.previous.0.datetimePol.attributes.authSt == 'disabled' |
| 215 |
- nm_remove_policy.previous.0.datetimePol.attributes.StratumValue == '9' |
| 216 |
- cm_remove_policy_again is not changed |
| 217 |
- nm_remove_policy_again is not changed |