<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Empty tag values when trying to create object in ansible in Automation/API Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-tag-values-when-trying-to-create-object-in-ansible/m-p/530120#M3312</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/241984"&gt;@zol123&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The default() empty set is not being used, it is passing through the "null" from your input variables. If you want to not set a tag if the input variable has tag=null, try omit for the default(), and ensure it gets used in the second parameter for the null use case (&lt;A href="https://docs.ansible.com/ansible/2.9/user_guide/playbooks_filters.html#defaulting-undefined-variables" target="_self"&gt;ref&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, ip_address/username/password are being deprecated, so please update your playbooks to use the &lt;FONT face="courier new,courier"&gt;provider&lt;/FONT&gt; parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;---
- name: Address objects with a loop
  hosts: '{{ target | default("host_labfw") }}'
  connection: local

  vars:
    device:
      ip_address: "{{ ip_address }}"
      username: "{{ username | default(omit) }}"
      password: "{{ password | default(omit) }}"
      api_key: "{{ api_key | default(omit) }}"
    address_objects:
      - {
        "address_type": "ip-netmask",
        "description": null,
        "name": "192.168.0.1_SOLARWINDS",
        "tag": "tag-one",
        "value": "192.168.0.1/32"
      }
      - {
        "address_type": "ip-netmask",
        "description": null,
        "name": "192.168.0.2_SOLARWINDS",
        "tag": null,
        "value": "192.168.0.2/32"
      }

  collections:
    - paloaltonetworks.panos

  tasks:
    - name: Create address objects
      paloaltonetworks.panos.panos_address_object:
        provider: '{{ device }}'
        name: '{{ item.name }}'
        value: '{{ item.value }}'
        description: '{{ item.description }}'
        tag: '{{ item.tag | default(omit, omit) }}'
        commit: false
      with_items: '{{ address_objects }}'&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;TASK [Create address objects] *******************************************************************************************************************************
changed: [host_labfw] =&amp;gt; (item={'address_type': 'ip-netmask', 'description': None, 'name': '192.168.0.1_SOLARWINDS', 'tag': 'tag-one', 'value': '192.168.0.1/32'})
changed: [host_labfw] =&amp;gt; (item={'address_type': 'ip-netmask', 'description': None, 'name': '192.168.0.2_SOLARWINDS', 'tag': None, 'value': '192.168.0.2/32'})

PLAY RECAP **************************************************************************************************************************************************
host_labfw                 : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
    <pubDate>Tue, 07 Feb 2023 14:56:28 GMT</pubDate>
    <dc:creator>JimmyHolland</dc:creator>
    <dc:date>2023-02-07T14:56:28Z</dc:date>
    <item>
      <title>Empty tag values when trying to create object in ansible</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-tag-values-when-trying-to-create-object-in-ansible/m-p/530113#M3311</link>
      <description>&lt;P&gt;In the examples i have seen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="java"&gt;    - name: Create address objects
      paloaltonetworks.panos.panos_address_object:
        ip_address: "{{inventory_hostname}}"
        username: " {{ username }} "
        password: " {{ password }}"
        name: '{{ item.name }}'
        value: '{{ item.value }}'
        description: '{{ item.description }}'
        tag: '{{ item.tag | default([]) }}'
        commit: false&lt;/LI-CODE&gt;&lt;P&gt;This seems to work, but when i try to create object with a loop with objects i have saved i get this error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;failed: [] (item={'value': 192.168.0.1/32', 'description': None, 'tag': None, 'name': 192.168.0.1_SOLARWINDS', 'address_type': 'ip-netmask'}) =&amp;gt; {"ansible_loop_var": "item", "changed": false, "item": {"address_type": "ip-netmask", "description": null, "name": "192.168.0.1_SOLARWINDS", "tag": null, "value": "192.168.0.1/32"}, "msg": "Failed create: 192.168.0.1_SOLARWINDS -&amp;gt; tag is invalid"}&lt;/LI-CODE&gt;&lt;P&gt;This is how the variable look that i try to use with a loop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"gathered": [&lt;BR /&gt;{&lt;BR /&gt;"address_type": "ip-netmask",&lt;BR /&gt;"description": null,&lt;BR /&gt;"name": "192.168.0.1_SOLARWINDS",&lt;BR /&gt;"tag": null,&lt;BR /&gt;"value": "192.168.0.1/32"&lt;BR /&gt;},&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do i miss anything?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 13:58:40 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-tag-values-when-trying-to-create-object-in-ansible/m-p/530113#M3311</guid>
      <dc:creator>zol123</dc:creator>
      <dc:date>2023-02-07T13:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: Empty tag values when trying to create object in ansible</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-tag-values-when-trying-to-create-object-in-ansible/m-p/530120#M3312</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/241984"&gt;@zol123&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The default() empty set is not being used, it is passing through the "null" from your input variables. If you want to not set a tag if the input variable has tag=null, try omit for the default(), and ensure it gets used in the second parameter for the null use case (&lt;A href="https://docs.ansible.com/ansible/2.9/user_guide/playbooks_filters.html#defaulting-undefined-variables" target="_self"&gt;ref&lt;/A&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, ip_address/username/password are being deprecated, so please update your playbooks to use the &lt;FONT face="courier new,courier"&gt;provider&lt;/FONT&gt; parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;---
- name: Address objects with a loop
  hosts: '{{ target | default("host_labfw") }}'
  connection: local

  vars:
    device:
      ip_address: "{{ ip_address }}"
      username: "{{ username | default(omit) }}"
      password: "{{ password | default(omit) }}"
      api_key: "{{ api_key | default(omit) }}"
    address_objects:
      - {
        "address_type": "ip-netmask",
        "description": null,
        "name": "192.168.0.1_SOLARWINDS",
        "tag": "tag-one",
        "value": "192.168.0.1/32"
      }
      - {
        "address_type": "ip-netmask",
        "description": null,
        "name": "192.168.0.2_SOLARWINDS",
        "tag": null,
        "value": "192.168.0.2/32"
      }

  collections:
    - paloaltonetworks.panos

  tasks:
    - name: Create address objects
      paloaltonetworks.panos.panos_address_object:
        provider: '{{ device }}'
        name: '{{ item.name }}'
        value: '{{ item.value }}'
        description: '{{ item.description }}'
        tag: '{{ item.tag | default(omit, omit) }}'
        commit: false
      with_items: '{{ address_objects }}'&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;TASK [Create address objects] *******************************************************************************************************************************
changed: [host_labfw] =&amp;gt; (item={'address_type': 'ip-netmask', 'description': None, 'name': '192.168.0.1_SOLARWINDS', 'tag': 'tag-one', 'value': '192.168.0.1/32'})
changed: [host_labfw] =&amp;gt; (item={'address_type': 'ip-netmask', 'description': None, 'name': '192.168.0.2_SOLARWINDS', 'tag': None, 'value': '192.168.0.2/32'})

PLAY RECAP **************************************************************************************************************************************************
host_labfw                 : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   &lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 14:56:28 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/empty-tag-values-when-trying-to-create-object-in-ansible/m-p/530120#M3312</guid>
      <dc:creator>JimmyHolland</dc:creator>
      <dc:date>2023-02-07T14:56:28Z</dc:date>
    </item>
  </channel>
</rss>

