CiscoDevNet / FMCAnsible

GNU General Public License v3.0
20 stars 25 forks source link

register_as variable for loop actions #12

Open vjsaisha opened 2 years ago

vjsaisha commented 2 years ago

When we are adding the objects through the loop function and using the register_as function it's not holding all the objects attributes only the last execution item is only holding.

Any way to achieve this?

vjsaisha commented 2 years ago
- hosts: all
  connection: httpapi
  vars:
    src_obj_host: 
      - 10.1.1.1
      - 10.1.1.2
    dst_obj_host:
      - 10.2.1.1
  tasks:
   - name: Get Domain UUID
     cisco.fmcansible.fmc_configuration:
        operation: getAllDomain
      register_as: domain
   - name: Create a network object type - Host
     cisco.fmcansible.fmc_configuration:
        operation: upsertHostObject
        data:
          name: 'IP-{{item}}'
          value: '{{item}}'
          type: Host
        path_params:
          domainUUID: '{{ domain[0].uuid }}'
        register_as: networkobjectcreated
      loop: '{{ src_obj_host + dst_obj_host }}'
   - name:  print infor
     debug:
         msg: '{{ networkobjectcreated}}'
b1r63r commented 2 weeks ago

Hopefully you have your answer a long time ago, but try the following

   - name: Create a network object type - Host
     cisco.fmcansible.fmc_configuration:
        operation: upsertHostObject
        data:
          name: 'IP-{{item}}'
          value: '{{item}}'
          type: Host
        path_params:
          domainUUID: '{{ domain[0].uuid }}'
      register: networkobjectcreated
      loop: '{{ src_obj_host + dst_obj_host }}'

That is move the register_as in the module data to register at the task level.