Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
yogesh_uit08
Explorer

Need help in validation of service object , json parsing

Hi Team,

I am using the show-objects api to  filter the service  objects and then i am trying to fetch the name and uid of the service object.

 

my code is working when only one name is present against the port  however if multiple name present it is not working .

Please help me to query json for provided port number and get all the service names agains that.

- name: ALL TCP service object
uri:
url: "https://{{hostname}}/web_api/show-objects"
validate_certs: False
method: POST
headers:
x-chkp-sid: "{{ login.json.sid }}"
body:
filter: "{{svc_port}}"
type: "service-tcp"
offset: 0
details-level: full
body_format: json
register: check_host_result
when: proto == 'tcp'

and then using set set_fact ansible module

- name: Checking if Source already exists
set_fact:
item_type_exists: true
svc_name: "{{ item['name'] }}"
svc_uid: "{{ item['uid'] }}"
with_items:
- "{{check_host_result.json.objects }}"
when:
- item['type'] is defined
- item['type'] == "service-tcp"
- item['port'] == '5000'

it is giving me only one service object name not all service names. I tried to search with jq also but there has also  issue for multiple names. 

 

used below jq-

jmesquery: '[? port=="5000"].{Name: name,uid: uid,port: port }'

I am new to the this and stuck here , Please help me,appreciate your help in advance

0 Kudos
0 Replies

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events