<?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 Need help in validation of service object , json parsing in Ansible</title>
    <link>https://community.checkpoint.com/t5/Ansible/Need-help-in-validation-of-service-object-json-parsing/m-p/85024#M317</link>
    <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;I am using the show-objects api to&amp;nbsp; filter the service&amp;nbsp; objects and then i am trying to fetch the name and uid of the service object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code is working when only one name is present against the port&amp;nbsp; however if multiple name present it is not working .&lt;/P&gt;&lt;P&gt;Please help me to query json for provided port number and get all the service names agains that.&lt;/P&gt;&lt;P&gt;- name: ALL TCP service object&lt;BR /&gt;uri:&lt;BR /&gt;url: "https://{{hostname}}/web_api/show-objects"&lt;BR /&gt;validate_certs: False&lt;BR /&gt;method: POST&lt;BR /&gt;headers:&lt;BR /&gt;x-chkp-sid: "{{ login.json.sid }}"&lt;BR /&gt;body:&lt;BR /&gt;filter: "{{svc_port}}"&lt;BR /&gt;type: "service-tcp"&lt;BR /&gt;offset: 0&lt;BR /&gt;details-level: full&lt;BR /&gt;body_format: json&lt;BR /&gt;register: check_host_result&lt;BR /&gt;when: proto == 'tcp'&lt;/P&gt;&lt;P&gt;and then using set set_fact ansible module&lt;/P&gt;&lt;P&gt;- name: Checking if Source already exists&lt;BR /&gt;set_fact:&lt;BR /&gt;item_type_exists: true&lt;BR /&gt;svc_name: "{{ item['name'] }}"&lt;BR /&gt;svc_uid: "{{ item['uid'] }}"&lt;BR /&gt;with_items:&lt;BR /&gt;- "{{check_host_result.json.objects }}"&lt;BR /&gt;when:&lt;BR /&gt;- item['type'] is defined&lt;BR /&gt;- item['type'] == "service-tcp"&lt;BR /&gt;- item['port'] == '5000'&lt;/P&gt;&lt;P&gt;it is giving me only one service object name not all service names. I tried to search with jq also but there has also&amp;nbsp; issue for multiple names.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;used below jq-&lt;/P&gt;&lt;P&gt;jmesquery: '[? port=="5000"].{Name: name,uid: uid,port: port }'&lt;/P&gt;&lt;P&gt;I am new to the this and stuck here , Please help me,appreciate your help in advance&lt;/P&gt;</description>
    <pubDate>Wed, 13 May 2020 07:38:31 GMT</pubDate>
    <dc:creator>yogesh_uit08</dc:creator>
    <dc:date>2020-05-13T07:38:31Z</dc:date>
    <item>
      <title>Need help in validation of service object , json parsing</title>
      <link>https://community.checkpoint.com/t5/Ansible/Need-help-in-validation-of-service-object-json-parsing/m-p/85024#M317</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;I am using the show-objects api to&amp;nbsp; filter the service&amp;nbsp; objects and then i am trying to fetch the name and uid of the service object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code is working when only one name is present against the port&amp;nbsp; however if multiple name present it is not working .&lt;/P&gt;&lt;P&gt;Please help me to query json for provided port number and get all the service names agains that.&lt;/P&gt;&lt;P&gt;- name: ALL TCP service object&lt;BR /&gt;uri:&lt;BR /&gt;url: "https://{{hostname}}/web_api/show-objects"&lt;BR /&gt;validate_certs: False&lt;BR /&gt;method: POST&lt;BR /&gt;headers:&lt;BR /&gt;x-chkp-sid: "{{ login.json.sid }}"&lt;BR /&gt;body:&lt;BR /&gt;filter: "{{svc_port}}"&lt;BR /&gt;type: "service-tcp"&lt;BR /&gt;offset: 0&lt;BR /&gt;details-level: full&lt;BR /&gt;body_format: json&lt;BR /&gt;register: check_host_result&lt;BR /&gt;when: proto == 'tcp'&lt;/P&gt;&lt;P&gt;and then using set set_fact ansible module&lt;/P&gt;&lt;P&gt;- name: Checking if Source already exists&lt;BR /&gt;set_fact:&lt;BR /&gt;item_type_exists: true&lt;BR /&gt;svc_name: "{{ item['name'] }}"&lt;BR /&gt;svc_uid: "{{ item['uid'] }}"&lt;BR /&gt;with_items:&lt;BR /&gt;- "{{check_host_result.json.objects }}"&lt;BR /&gt;when:&lt;BR /&gt;- item['type'] is defined&lt;BR /&gt;- item['type'] == "service-tcp"&lt;BR /&gt;- item['port'] == '5000'&lt;/P&gt;&lt;P&gt;it is giving me only one service object name not all service names. I tried to search with jq also but there has also&amp;nbsp; issue for multiple names.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;used below jq-&lt;/P&gt;&lt;P&gt;jmesquery: '[? port=="5000"].{Name: name,uid: uid,port: port }'&lt;/P&gt;&lt;P&gt;I am new to the this and stuck here , Please help me,appreciate your help in advance&lt;/P&gt;</description>
      <pubDate>Wed, 13 May 2020 07:38:31 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Ansible/Need-help-in-validation-of-service-object-json-parsing/m-p/85024#M317</guid>
      <dc:creator>yogesh_uit08</dc:creator>
      <dc:date>2020-05-13T07:38:31Z</dc:date>
    </item>
  </channel>
</rss>

