diff --git a/ansible/roles/secrets/tasks/secret_group.yml b/ansible/roles/secrets/tasks/secret_group.yml index b80a2816c..994a67a50 100644 --- a/ansible/roles/secrets/tasks/secret_group.yml +++ b/ansible/roles/secrets/tasks/secret_group.yml @@ -6,20 +6,27 @@ loop_control: loop_var: single_secret +- name: Initialize secret group associations + ansible.builtin.set_fact: + secrets_group_associations: [] + +- name: Build secret group associations + ansible.builtin.set_fact: + secrets_group_associations: "{{ secrets_group_associations + [association] }}" + vars: + association: + access_type: "{{ secrets_list.access_type }}" + secret_type: "{{ secrets_list.secret_type }}" + secret: "{{ secrets_list.name }}" + loop: "{{ item.value }}" + loop_control: + loop_var: secrets_list + - name: Create the Secret Group networktocode.nautobot.secrets_group: url: "{{ nautobot_url }}" token: "{{ nautobot_token }}" name: "{{ item.key }}" - -- name: Associate the secrets to the group - networktocode.nautobot.secrets_groups_association: - url: "{{ nautobot_url }}" - token: "{{ nautobot_token }}" - secrets_group: "{{ item.key }}" - access_type: "{{ secrets_list.access_type }}" - secret_type: "{{ secrets_list.secret_type }}" - secret: "{{ secrets_list.name }}" - loop: "{{ item.value }}" - loop_control: - loop_var: secrets_list + secrets: + state: merge + objects: "{{ secrets_group_associations }}"