nautobot / nautobot-ansible

Ansible Collection for managing Nautobot Data
https://nautobot-ansible.readthedocs.io/en/latest/
GNU General Public License v3.0
46 stars 31 forks source link

Adding tags on a record optionally shouldn't remove existing tags #354

Open chris-tomkins-flexgrid opened 4 months ago

chris-tomkins-flexgrid commented 4 months ago
ISSUE TYPE
SOFTWARE VERSIONS
pynautobot

2.2.0

Ansible:

2.16.0

Nautobot:

2.2.4

Collection:

5.2.1

SUMMARY

Adding tags on a record optionally shouldn't remove existing tags

STEPS TO REPRODUCE
- name: Creating prefix records in Nautobot, tagged with record-edited-by-ansible
  when: not temporaryskiprun and upstream_agg_switch is defined
  networktocode.nautobot.prefix:
    api_version: "2.1"
    prefix: "{{wansubnetusuallyslash29}}/29"
    location:
      name: "{{nautobot_site}}"
    namespace: "INTERNET.inet.0"
    state: present
    status: "{{'Active' if not awaitingfirstprovision else 'Reserved'}}"
    tags:
      - "Record edited by Ansible"
    tenant: "{{nautobot_tenant}}"
    token: "{{nautobot_read_write_token}}"
    type: Network
    url: https://{{nautobot_api_ip}}
    validate_certs: false # TODO - sort the certs on Nautobot so this isn't required
    vlan:
      name: "{{inventory_hostname|replace(\"-\", \".\")|lower}}.inner"
      site: "{{hostvars[upstream_agg_switch].nautobot_site}}"
      tenant: "{{nautobot_tenant}}"
EXPECTED RESULTS

I would expect to optionally be able to specify whether tags should be overwritten or additive.

ACTUAL RESULTS

Other useful tags unrelated to this Ansible play were removed:

TASK [nautobot_cpe : Creating prefix records in Nautobot, tagged with record-edited-by-ansible] ************************************
--- before
+++ after
@@ -1,4 +1,2 @@
 tags:
-- 484d9663-6ca2-4625-b54e-6eb896083722
 - f9a4e6f3-c27e-49a1-87e9-a9b92d7ce5c6
-- 2ce879e9-28c1-4056-8308-e4d1b1ef5b77
jvanderaa commented 4 months ago

I think we may be looking at needing to have to convert the modules over to a resource model style module with this. So that we can give the options on the modules to support declarative models (the way it is today) and the other idea of supporting of merging data together, which would be taking what is there already, and adding to it rather than just making it appear as declared.

chris-tomkins-flexgrid commented 4 months ago

Thanks @jvanderaa. So it feels like in the near term, the only solution here is to make a separate direct API call to handle tags, without using the actual Ansible module?

chris-tomkins-flexgrid commented 4 months ago

And, for the long term resolution - sounds reasonable.

jvanderaa commented 4 months ago

It would be a 2 or 3 steps.

Task 1: Grab the current tags that the object has (when it has already been created - yep, this isn't ideal) Task 2: Update the tags

jvanderaa commented 4 months ago

It's really a place at which point that tags and Ansible have a few different ideas.