Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ghost opened this issue May 16, 2024 · 5 comments
Open

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

ghost opened this issue May 16, 2024 · 5 comments

Comments

@ghost
Copy link

ghost commented May 16, 2024

ISSUE TYPE
  • Feature Idea
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
Copy link
Contributor

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.

@ghost
Copy link
Author

ghost commented May 20, 2024

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?

@ghost
Copy link
Author

ghost commented May 20, 2024

And, for the long term resolution - sounds reasonable.

@jvanderaa
Copy link
Contributor

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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant