Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions plugins/doc_fragments/aci.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,21 @@ class ModuleDocFragment(object):
suppress_verification:
description:
- If C(true), a verifying GET will not be sent after a POST update to APIC.
- If the value is not specified in the task, the value of environment variable C(ACI_NO_VERIFICATION) will be used instead.
- If the value is not specified in the task, the value of environment variable C(ACI_SUPPRESS_VERIFICATION) will be used instead.
- The default value is C(false).
- WARNING - This causes the current return value to be set to the proposed value.
- The current object including default values will be unverifiable in a single task.
type: bool
aliases: [ no_verification, no_verify, suppress_verify ]
aliases: [ no_verification, no_verify, suppress_verify, ignore_verify, ignore_verification ]
suppress_previous:
description:
- If C(true), a GET to check previous will not be sent before a POST update to APIC.
- If the value is not specified in the task, the value of environment variable C(ACI_SUPPRESS_PREVIOUS) will be used instead.
- The default value is C(false).
- WARNING - This causes the previous return value to be empty.
- The previous state of the object will not be checked and the POST update will contain all properties.
type: bool
aliases: [ no_previous, ignore_previous ]
seealso:
- ref: aci_guide
description: Detailed information on how to manage your ACI infrastructure using Ansible.
Expand Down
44 changes: 32 additions & 12 deletions plugins/module_utils/aci.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ def aci_argument_spec():
use_ssl=dict(type="bool", fallback=(env_fallback, ["ACI_USE_SSL"])),
validate_certs=dict(type="bool", fallback=(env_fallback, ["ACI_VALIDATE_CERTS"])),
output_path=dict(type="str", fallback=(env_fallback, ["ACI_OUTPUT_PATH"])),
suppress_verification=dict(type="bool", aliases=["no_verification", "no_verify", "suppress_verify"], fallback=(env_fallback, ["ACI_NO_VERIFICATION"])),
suppress_verification=dict(
type="bool",
aliases=["no_verification", "no_verify", "suppress_verify", "ignore_verify", "ignore_verification"],
fallback=(env_fallback, ["ACI_SUPPRESS_VERIFICATION"]),
),
suppress_previous=dict(type="bool", aliases=["no_previous", "ignore_previous"], fallback=(env_fallback, ["ACI_SUPPRESS_PREVIOUS"])),
)


Expand Down Expand Up @@ -420,6 +425,9 @@ def __init__(self, module):
# get no verify flag
self.suppress_verification = self.params.get("suppress_verification")

# get suppress previous flag
self.suppress_previous = self.params.get("suppress_previous")

# Ensure protocol is set
self.define_protocol()

Expand Down Expand Up @@ -1302,7 +1310,7 @@ def delete_config(self):
"""
self.proposed = dict()

if not self.existing:
if not self.existing and not self.suppress_previous:
return
elif not self.module.check_mode:
# Sign and encode request as to APIC's wishes
Expand Down Expand Up @@ -1429,10 +1437,30 @@ def get_existing(self):
that this method can be used to supply the existing configuration when using the get_diff method. The response, status,
and existing configuration will be added to the self.result dictionary.
"""
uri = self.url + self.filter_string
if self.suppress_previous:
self.existing = []
return

uri = self.url + self.filter_string
self.api_call("GET", uri, data=None, return_response=False)

def __get_existing_validation(self, changed):
"""
This method is used to get the existing object(s) state after a config change has been completed.
It will not get the object(s) state if there is no change or suppress_verification is enabled.
When suppress_verification is enabled, the existing will be set to proposed if there was a change or suppress_previous is enabled.
"""
if self.suppress_verification:
if changed or self.suppress_previous:
self.result["current_verified"] = False
self.existing = [self.proposed] if self.proposed != {} else []
else:
# existing already equals the previous
self.result["current_verified"] = True
elif changed:
uri = self.url + self.filter_string
self.api_call("GET", uri, data=None, return_response=False)

@staticmethod
def get_nested_config(proposed_child, existing_children):
"""
Expand Down Expand Up @@ -1597,15 +1625,7 @@ def exit_json(self, filter_existing=None, **kwargs):
if "state" in self.params:
self.original = self.existing
if self.params.get("state") in ("absent", "present"):
if self.suppress_verification:
if self.result["changed"]:
self.result["current_verified"] = False
self.existing = [self.proposed]
else:
self.result["current_verified"] = True
# exisiting already equals the previous
else:
self.get_existing()
self.__get_existing_validation(self.result["changed"])

# if self.module._diff and self.original != self.existing:
# self.result['diff'] = dict(
Expand Down
143 changes: 143 additions & 0 deletions tests/integration/targets/aci_bd_subnet/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,149 @@
- create_subnet2_5.sent.fvSubnet.children.0.fvRsBDSubnetToProfile.attributes.tnRtctrlProfileName == 'default'
when: version.current.0.topSystem.attributes.version is version('5', '>=')

# TEST NO PREVIOUS
- name: create bd subnet with no previous (check mode)
cisco.aci.aci_bd_subnet: &aci_bd_subnet_no_previous
<<: *aci_subnet_present
subnet_name: anstest_no_previous
gateway: 10.101.101.10
mask: 25
no_previous: true
check_mode: true
register: bd_subnet_present_no_previous_cm

- name: create bd subnet with no previous
cisco.aci.aci_bd_subnet:
<<: *aci_bd_subnet_no_previous
register: bd_subnet_present_no_previous

- name: create bd subnet with no previous again
cisco.aci.aci_bd_subnet:
<<: *aci_bd_subnet_no_previous
register: bd_subnet_present_no_previous_again

- name: update bd subnet with no previous
cisco.aci.aci_bd_subnet:
<<: *aci_bd_subnet_no_previous
descr: Ansible Test no previous
register: update_bd_subnet_present_no_previous

- name: delete bd subnet with no previous
cisco.aci.aci_bd_subnet:
<<: *aci_bd_subnet_no_previous
state: absent
register: delete_bd_subnet_present_no_previous

- name: delete bd subnet with no previous again
cisco.aci.aci_bd_subnet:
<<: *aci_bd_subnet_no_previous
state: absent
register: delete_bd_subnet_present_no_previous_again

- name: no previous asserts
ansible.builtin.assert:
that:
- bd_subnet_present_no_previous_cm is changed
- bd_subnet_present_no_previous_cm.current == []
- bd_subnet_present_no_previous_cm.previous == []
- bd_subnet_present_no_previous_cm.proposed.fvSubnet.attributes.dn == "uni/tn-ansible_test/BD-anstest/subnet-[10.101.101.10/25]"
- bd_subnet_present_no_previous_cm.proposed.fvSubnet.attributes.descr == "Ansible Test"
- bd_subnet_present_no_previous_cm.proposed.fvSubnet.attributes.annotation == "orchestrator:ansible"
- bd_subnet_present_no_previous is changed
- bd_subnet_present_no_previous.current.0.fvSubnet.attributes.dn == "uni/tn-ansible_test/BD-anstest/subnet-[10.101.101.10/25]"
- bd_subnet_present_no_previous.current.0.fvSubnet.attributes.annotation == "orchestrator:ansible"
- bd_subnet_present_no_previous.current.0.fvSubnet.attributes.descr == "Ansible Test"
- bd_subnet_present_no_previous.proposed.fvSubnet.attributes.dn == "uni/tn-ansible_test/BD-anstest/subnet-[10.101.101.10/25]"
- bd_subnet_present_no_previous.proposed.fvSubnet.attributes.annotation == "orchestrator:ansible"
- bd_subnet_present_no_previous.proposed.fvSubnet.attributes.descr == "Ansible Test"
- bd_subnet_present_no_previous.previous == []
- bd_subnet_present_no_previous_again is changed
- bd_subnet_present_no_previous_again.current == bd_subnet_present_no_previous.current
- bd_subnet_present_no_previous_again.proposed == bd_subnet_present_no_previous.proposed
- bd_subnet_present_no_previous_again.previous == []
- update_bd_subnet_present_no_previous is changed
- update_bd_subnet_present_no_previous.current.0.fvSubnet.attributes.dn == "uni/tn-ansible_test/BD-anstest/subnet-[10.101.101.10/25]"
- update_bd_subnet_present_no_previous.current.0.fvSubnet.attributes.annotation == "orchestrator:ansible"
- update_bd_subnet_present_no_previous.current.0.fvSubnet.attributes.descr == "Ansible Test no previous"
- delete_bd_subnet_present_no_previous is changed
- delete_bd_subnet_present_no_previous.current == []
- delete_bd_subnet_present_no_previous.previous == []
- delete_bd_subnet_present_no_previous.proposed == {}
- delete_bd_subnet_present_no_previous_again is changed
- delete_bd_subnet_present_no_previous_again.current == []
- delete_bd_subnet_present_no_previous_again.previous == []
- delete_bd_subnet_present_no_previous_again.proposed == {}

# TEST NO PREVIOUS & NO VERIFICATION
- name: create bd subnet with no previous & no verify (check mode)
cisco.aci.aci_bd_subnet: &aci_bd_subnet_no_lb_no_v
<<: *aci_subnet_present
subnet_name: anstest_no_lb_no_v
gateway: 10.102.101.12
mask: 25
no_previous: true
no_verify: true
check_mode: true
register: bd_subnet_present_no_lb_no_v_cm

- name: create bd subnet with no previous & no verify
cisco.aci.aci_bd_subnet:
<<: *aci_bd_subnet_no_lb_no_v
register: bd_subnet_present_no_lb_no_v

- name: create bd subnet with no previous again & no verify
cisco.aci.aci_bd_subnet:
<<: *aci_bd_subnet_no_lb_no_v
register: bd_subnet_present_no_lb_no_v_again

- name: update bd subnet with no previous & no verify
cisco.aci.aci_bd_subnet:
<<: *aci_bd_subnet_no_lb_no_v
descr: Ansible Test no previous & no verify
register: update_bd_subnet_present_no_lb_no_v

- name: delete bd subnet with no previous & no verify
cisco.aci.aci_bd_subnet:
<<: *aci_bd_subnet_no_lb_no_v
state: absent
register: delete_bd_subnet_present_no_lb_no_v

- name: delete bd subnet with no previous again & no verify
cisco.aci.aci_bd_subnet:
<<: *aci_bd_subnet_no_lb_no_v
state: absent
register: delete_bd_subnet_present_no_lb_no_v_again

- name: no previous & no verify asserts
ansible.builtin.assert:
that:
- bd_subnet_present_no_lb_no_v_cm is changed
- bd_subnet_present_no_lb_no_v_cm.current.0 == bd_subnet_present_no_lb_no_v_cm.proposed
- bd_subnet_present_no_lb_no_v_cm.previous == []
- bd_subnet_present_no_lb_no_v_cm.proposed.fvSubnet.attributes.dn == "uni/tn-ansible_test/BD-anstest/subnet-[10.102.101.12/25]"
- bd_subnet_present_no_lb_no_v_cm.proposed.fvSubnet.attributes.descr == "Ansible Test"
- bd_subnet_present_no_lb_no_v_cm.proposed.fvSubnet.attributes.annotation == "orchestrator:ansible"
- bd_subnet_present_no_lb_no_v is changed
- bd_subnet_present_no_lb_no_v.current.0 == bd_subnet_present_no_lb_no_v.proposed
- bd_subnet_present_no_lb_no_v.previous == []
- bd_subnet_present_no_lb_no_v_again is changed
- bd_subnet_present_no_lb_no_v_again.current == bd_subnet_present_no_lb_no_v.current
- bd_subnet_present_no_lb_no_v_again.proposed == bd_subnet_present_no_lb_no_v.proposed
- bd_subnet_present_no_lb_no_v_again.previous == []
- update_bd_subnet_present_no_lb_no_v is changed
- update_bd_subnet_present_no_lb_no_v.current.0 == update_bd_subnet_present_no_lb_no_v.proposed
- update_bd_subnet_present_no_lb_no_v.current.0.fvSubnet.attributes.dn == "uni/tn-ansible_test/BD-anstest/subnet-[10.102.101.12/25]"
- update_bd_subnet_present_no_lb_no_v.current.0.fvSubnet.attributes.annotation == "orchestrator:ansible"
- update_bd_subnet_present_no_lb_no_v.current.0.fvSubnet.attributes.descr == "Ansible Test no previous & no verify"
- delete_bd_subnet_present_no_lb_no_v is changed
- delete_bd_subnet_present_no_lb_no_v.current == []
- delete_bd_subnet_present_no_lb_no_v.previous == []
- delete_bd_subnet_present_no_lb_no_v.proposed == {}
- delete_bd_subnet_present_no_lb_no_v_again is changed
- delete_bd_subnet_present_no_lb_no_v_again.current == []
- delete_bd_subnet_present_no_lb_no_v_again.previous == []
- delete_bd_subnet_present_no_lb_no_v_again.proposed == {}

- name: get all subnets
cisco.aci.aci_bd_subnet: &aci_query
<<: *aci_tenant_present
Expand Down
Loading