<?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: Listing the members of a network group in API / CLI Discussion</title>
    <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/58887#M3735</link>
    <description>&lt;P&gt;I get the below error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;membername = jsonGroups[0][group]['members'][member]['name'].replace(',', ';')&lt;BR /&gt;TypeError: string indices must be integers&lt;/P&gt;&lt;P&gt;any ideas?&lt;/P&gt;</description>
    <pubDate>Wed, 24 Jul 2019 09:50:33 GMT</pubDate>
    <dc:creator>theodosis</dc:creator>
    <dc:date>2019-07-24T09:50:33Z</dc:date>
    <item>
      <title>Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/10705#M838</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We are doing audits and cleanup of the network objects in our policy rules. I need to provide a list of servers in a specific network group. I have tried "$MDS_FWDIR/scripts/web_api_show_package.sh -k &amp;lt;policy_name&amp;gt;" but that seems to work only with the VS packages. I am running R80.10 on the management server.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Eric&lt;/P&gt;&lt;P&gt;Senior Systems Administrator&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2018 12:41:18 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/10705#M838</guid>
      <dc:creator>Eric_Speake</dc:creator>
      <dc:date>2018-07-19T12:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/10706#M839</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've written a small python script that exports all groups and the related hosts within it (host, network, address range and security gateway objects) as a csv file. It also shows empty groups, that were possible forgotten about. The script works only for IPv4 objects!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;# example csv header:&lt;BR /&gt;# groupname,groupuid,membername,membertype,memberip,membersubnetmask,memberuid&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use the script and filter for the required group in the related group name column. The script usage is shown by specifying the -h parameter. Just make sure that you copy the whole folder within the zip as the subfolder "mgmt_api_lib" is also required (the script has only been tested with Python 2.7 - which is preinstalled within R80).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2018 13:36:05 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/10706#M839</guid>
      <dc:creator>Maik</dc:creator>
      <dc:date>2018-07-19T13:36:05Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/10707#M840</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm going to move this to &lt;A href="https://community.checkpoint.com/space/2003"&gt;Developers (Code Hub)&lt;/A&gt;‌&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2018 15:32:03 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/10707#M840</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2018-07-19T15:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/10708#M841</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Very good work, Maik.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2018 15:38:41 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/10708#M841</guid>
      <dc:creator>Robert_Decker</dc:creator>
      <dc:date>2018-07-19T15:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/58887#M3735</link>
      <description>&lt;P&gt;I get the below error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;membername = jsonGroups[0][group]['members'][member]['name'].replace(',', ';')&lt;BR /&gt;TypeError: string indices must be integers&lt;/P&gt;&lt;P&gt;any ideas?&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jul 2019 09:50:33 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/58887#M3735</guid>
      <dc:creator>theodosis</dc:creator>
      <dc:date>2019-07-24T09:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/73676#M4325</link>
      <description>&lt;P&gt;This bash script may not be the most efficient, but it works for us on R80.20.&amp;nbsp;&lt;/P&gt;&lt;P&gt;To be run on the management server.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jan 2020 14:47:44 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/73676#M4325</guid>
      <dc:creator>emma_on</dc:creator>
      <dc:date>2020-01-29T14:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/74831#M4359</link>
      <description>&lt;P&gt;I am getting he same error. Did you get the solution for this issue ?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 17:24:50 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/74831#M4359</guid>
      <dc:creator>mperveiz</dc:creator>
      <dc:date>2020-02-11T17:24:50Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/74843#M4364</link>
      <description>&lt;P&gt;Where will the output file go ?&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 18:38:37 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/74843#M4364</guid>
      <dc:creator>mperveiz</dc:creator>
      <dc:date>2020-02-11T18:38:37Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/74844#M4365</link>
      <description>&lt;P&gt;Did you find the solution to this error.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 18:39:28 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/74844#M4365</guid>
      <dc:creator>mperveiz</dc:creator>
      <dc:date>2020-02-11T18:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/74953#M4371</link>
      <description>&lt;P&gt;That's up to you.&amp;nbsp; It's standard bash.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will write the output to std_out (usually the terminal):&lt;/P&gt;&lt;P&gt;# ./list-group-info.bsh&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will write the output to both std_out and the file you specify:&lt;/P&gt;&lt;P&gt;# ./list-group-info.bsh | tee /var/tmp/group-list.out&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will write the output to the file you specify:&lt;/P&gt;&lt;P&gt;# ./list-group-info.bsh &amp;gt; /var/tmp/group-list.out&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 10:30:34 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/74953#M4371</guid>
      <dc:creator>emma_on</dc:creator>
      <dc:date>2020-02-12T10:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/76420#M4444</link>
      <description>&lt;P&gt;hello friend,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can you briefly describe this, can we export the objects of the network group of the checkpoint management server to the csv file&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 06:13:31 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/76420#M4444</guid>
      <dc:creator>Rabindra_Khadka</dc:creator>
      <dc:date>2020-02-26T06:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/119492#M5874</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;If you use ansible. I have a working solution I created&lt;BR /&gt;&lt;STRONG&gt;Export_Groups_Host_Network_AddressRange_in_a_Group_to_CSV.yml&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Note&lt;/FONT&gt;&lt;/STRONG&gt;:&amp;nbsp;to use&lt;FONT color="#FF0000"&gt; json_query&lt;/FONT&gt;&amp;nbsp;&lt;FONT color="#FF0000"&gt;filter&lt;/FONT&gt; run "&lt;STRONG&gt;pip install jmespath&lt;/STRONG&gt;" on the command line&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;---
- name: Get Hosts, Networks, Subgroups, Address-Range in a Group and  export to CSV 
  hosts: check_point
  connection: httpapi
  gather_facts: False

  # perform your authentication 
  vars_files:
    - 'login.yml'

  tasks:

  # create group, if group exist, do nothing
  - name: if-group-doesn't-exist-create-one
    check_point.mgmt.cp_mgmt_group:
      name: Your_Group
      state: present
    delegate_to: Your_Domain
    ignore_errors: yes

  # grab all the details in the group
  # Note: if we have about 3000 objects 
  # or thousands of objectin a group, becaus of overload
  # then use details_level: standard
  # this will exclude any comments created in a object
  - name: get-details-from-group
    check_point.mgmt.cp_mgmt_group_facts:
      name: Your_Group
      details_level: full
    register: result
    delegate_to: Your_Domain
    ignore_errors: yes

  # apply filter and get only members present in the group
  - name: filter-result-from-group-facts
    set_fact:
      filtered_group_facts: "{{ result['ansible_facts']['group']['members'] }}"
    register: device
    ignore_errors: yes

  # get only address range present in the group using json query filter run "pip install jmespath" on the command line to enable this filter
  - name: get-address-range-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        comments: comments,
        "ipv4-address-first": "ipv4-address-first",
        "ipv4-address-last": "ipv4-address-last",
        name: name
        }
      new_address_range: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_address_range
    debug:
      var: new_address_range 
    no_log: yes
    ignore_errors: yes


  # get only host present in the group using json query filter
  - name: get-hosts-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        comments: comments,
        "ipv4-address": "ipv4-address",
        name: name
        }
      new_host: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_host
    debug:
      var: new_host 
    no_log: yes
    ignore_errors: yes

  # get only network present in the group using json query filter
  - name: get-networks-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        name: name
        "subnet-mask": "subnet-mask"
        subnet4: subnet4,
        comments: comments
        }
      new_network: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_network
    debug:
      var: new_network 
    no_log: yes
    ignore_errors: yes

  # get only subgroup present in the group using json query filter
  - name: get-subgroup-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        name: name,
        comments: comments
        }
      new_group: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_group
    debug:
      var: new_group
    no_log: yes
    ignore_errors: yes

  # extract only address range
  - name: get-only-address-range
    set_fact:
      address_range_lists: "{{ result_address_range.new_address_range | rejectattr('ipv4-address-first', 'match', 'None') | flatten }}"
    ignore_errors: yes

  # extract only host if it exist
  - name: get-only-host
    set_fact:
      host_lists: "{{ (result_network.new_network | rejectattr('subnet-mask', 'match', 'None') | flatten) }}"
    ignore_errors: yes

  # extract only network if it exist
  - name: get-only-network
    set_fact:
      network_lists: "{{ result_host.new_host | rejectattr('ipv4-address','match', 'None') | flatten }}"
    ignore_errors: yes

  # extract group if it exist
  - name: get-only-group
    set_fact:
      group_lists: "{{ result_group.new_group | selectattr('type','match', 'group') | flatten }}"
#     group_lists: "{{ result_group.new_group | rejectattr('members','match', 'None') | flatten }}"
    ignore_errors: yes

  # append the list so we can group them
  - name: combine list
    set_fact:
      list_merged: "{{ network_lists + host_lists + group_lists + address_range_lists }}"
    ignore_errors: yes

  # create log files
  - name: copy-file-to-log
    local_action:
      module: copy
      content: "{{ list_merged | to_nice_yaml}}"
      dest: tmp/log.yml
    changed_when: false

#   # run python script to convert yaml to csv
  - name: run-script-to-do-conversion
    script:
      cmd: /usr/bin/python3 ./Yaml_to_CSV.py

# Note to use json_query file run "pip install jmespath" on the command line

# Note: create a diretory folder 'tmp' and create a file 'log.yml' inside the directory "tmp/log.yml"

# We will parse data into log.yml and resuse it in our python script&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;Credentials&lt;BR /&gt;login.yml&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ansible_user: Enter_Username
ansible_password: Enter_Password
ansible_httpapi_validate_certs: False
ansible_network_os: check_point.mgmt.checkpoint
ansible_python_interpreter: "python"

# Note: Username and Password you use to log into SmartConsole Checkpoint&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;hosts&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[check_point]
checkpoint ansible_host=Enter_Address_of_Host

[check_point:vars]
ansible_python_interpreter= "python"

[cma]
Domain_1 ansible_host=Enter_Address_of_Host ansible_checkpoint_domain=Domain_1

Domain_2 ansible_host=Enter_Address_of_Host ansible_checkpoint_domain=Domain_2

Domain_3 ansible_host=Enter_Address_of_Host ansible_checkpoint_domain=Domain_3

[cmas:vars]
ansible_python_interpreter= "python"

# Note: use Domain_1, Domain_2, Domain_3, etc. in case of Multiple Domains&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Yaml_to_CSV.py&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import csv
import yaml

# creating header for the csv file
fields = {
    'name' : 'Name',
    'ipv4-address' : 'IP',
    'subnet4' : 'Subnet4',
    'subnet-mask' : 'Subnet-Mask',
    'ipv4-address-first' : 'IPv4-Address-First',
    'ipv4-address-last' : 'IPv4-Address-Last',
    'comments' : 'Comments',
    'type' : 'Type',
}

# open fileand write header data to file
with open('Converted_Output.csv', 'w', newline='') as f_output:
    csv_output = csv.DictWriter(f_output, fieldnames=fields.values())
    csv_output.writeheader()

# open log file and key values to file
    for filename in ['tmp/log.yml']:
        with open(filename) as f_input:
            for row_yaml in yaml.safe_load(f_input):
                row_csv = {fields[key] : value for key, value in row_yaml.items()}
                csv_output.writerow(row_csv)

# rember to create a file "Converted_Output.csv"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Finally, your&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- Converted_Output.csv&lt;/FONT&gt;,&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- host,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- login.yml&lt;/FONT&gt;,&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- tmp/log.yml&amp;nbsp; -&amp;gt; a folder "tmp" with a file "log.yml"&lt;BR /&gt;&lt;/FONT&gt;-&amp;nbsp; &lt;FONT color="#FF0000"&gt;playbook&amp;nbsp;&lt;/FONT&gt;(&lt;STRONG&gt;Export_Groups_Host_Network_AddressRange_in_a_Group_to_CSV.yml&lt;/STRONG&gt;) should be in one directory .&lt;BR /&gt;&lt;BR /&gt;You can reach out to me if you are confused or you have more questions&lt;/P&gt;</description>
      <pubDate>Wed, 26 May 2021 17:59:07 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/119492#M5874</guid>
      <dc:creator>ukohae</dc:creator>
      <dc:date>2021-05-26T17:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/119496#M5875</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;If you use ansible. I have a working solution I created&lt;BR /&gt;&lt;STRONG&gt;Export_Groups_Host_Network_AddressRange_in_a_Group_to_CSV.yml&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Note&lt;/FONT&gt;&lt;/STRONG&gt;:&amp;nbsp;to use&lt;FONT color="#FF0000"&gt; json_query&lt;/FONT&gt;&amp;nbsp;&lt;FONT color="#FF0000"&gt;filter&lt;/FONT&gt; run "&lt;STRONG&gt;pip install jmespath&lt;/STRONG&gt;" on the command line&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;---
- name: Get Hosts, Networks, Subgroups, Address-Range in a Group and  export to CSV 
  hosts: check_point
  connection: httpapi
  gather_facts: False

  # perform your authentication 
  vars_files:
    - 'login.yml'

  tasks:

  # create group, if group exist, do nothing
  - name: if-group-doesn't-exist-create-one
    check_point.mgmt.cp_mgmt_group:
      name: Your_Group
      state: present
    delegate_to: Your_Domain
    ignore_errors: yes

  # grab all the details in the group
  # Note: if we have about 3000 objects 
  # or thousands of objectin a group, becaus of overload
  # then use details_level: standard
  # this will exclude any comments created in a object
  - name: get-details-from-group
    check_point.mgmt.cp_mgmt_group_facts:
      name: Your_Group
      details_level: full
    register: result
    delegate_to: Your_Domain
    ignore_errors: yes

  # apply filter and get only members present in the group
  - name: filter-result-from-group-facts
    set_fact:
      filtered_group_facts: "{{ result['ansible_facts']['group']['members'] }}"
    register: device
    ignore_errors: yes

  # get only address range present in the group using json query filter run "pip install jmespath" on the command line to enable this filter
  - name: get-address-range-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        comments: comments,
        "ipv4-address-first": "ipv4-address-first",
        "ipv4-address-last": "ipv4-address-last",
        name: name
        }
      new_address_range: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_address_range
    debug:
      var: new_address_range 
    no_log: yes
    ignore_errors: yes


  # get only host present in the group using json query filter
  - name: get-hosts-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        comments: comments,
        "ipv4-address": "ipv4-address",
        name: name
        }
      new_host: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_host
    debug:
      var: new_host 
    no_log: yes
    ignore_errors: yes

  # get only network present in the group using json query filter
  - name: get-networks-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        name: name
        "subnet-mask": "subnet-mask"
        subnet4: subnet4,
        comments: comments
        }
      new_network: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_network
    debug:
      var: new_network 
    no_log: yes
    ignore_errors: yes

  # get only subgroup present in the group using json query filter
  - name: get-subgroup-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        name: name,
        comments: comments
        }
      new_group: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_group
    debug:
      var: new_group
    no_log: yes
    ignore_errors: yes

  # extract only address range
  - name: get-only-address-range
    set_fact:
      address_range_lists: "{{ result_address_range.new_address_range | rejectattr('ipv4-address-first', 'match', 'None') | flatten }}"
    ignore_errors: yes

  # extract only host if it exist
  - name: get-only-host
    set_fact:
      host_lists: "{{ (result_network.new_network | rejectattr('subnet-mask', 'match', 'None') | flatten) }}"
    ignore_errors: yes

  # extract only network if it exist
  - name: get-only-network
    set_fact:
      network_lists: "{{ result_host.new_host | rejectattr('ipv4-address','match', 'None') | flatten }}"
    ignore_errors: yes

  # extract group if it exist
  - name: get-only-group
    set_fact:
      group_lists: "{{ result_group.new_group | selectattr('type','match', 'group') | flatten }}"
#     group_lists: "{{ result_group.new_group | rejectattr('members','match', 'None') | flatten }}"
    ignore_errors: yes

  # append the list so we can group them
  - name: combine list
    set_fact:
      list_merged: "{{ network_lists + host_lists + group_lists + address_range_lists }}"
    ignore_errors: yes

  # create log files
  - name: copy-file-to-log
    local_action:
      module: copy
      content: "{{ list_merged | to_nice_yaml}}"
      dest: tmp/log.yml
    changed_when: false

#   # run python script to convert yaml to csv
  - name: run-script-to-do-conversion
    script:
      cmd: /usr/bin/python3 ./Yaml_to_CSV.py

# Note to use json_query file run "pip install jmespath" on the command line

# Note: create a diretory folder 'tmp' and create a file 'log.yml' inside the directory "tmp/log.yml"

# We will parse data into log.yml and resuse it in our python script&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;Credentials&lt;BR /&gt;login.yml&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ansible_user: Enter_Username
ansible_password: Enter_Password
ansible_httpapi_validate_certs: False
ansible_network_os: check_point.mgmt.checkpoint
ansible_python_interpreter: "python"

# Note: Username and Password you use to log into SmartConsole Checkpoint&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;hosts&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[check_point]
checkpoint ansible_host=Enter_Address_of_Host

[check_point:vars]
ansible_python_interpreter= "python"

[cma]
Domain_1 ansible_host=Enter_Address_of_Host ansible_checkpoint_domain=Domain_1

Domain_2 ansible_host=Enter_Address_of_Host ansible_checkpoint_domain=Domain_2

Domain_3 ansible_host=Enter_Address_of_Host ansible_checkpoint_domain=Domain_3

[cmas:vars]
ansible_python_interpreter= "python"

# Note: use Domain_1, Domain_2, Domain_3, etc. in case of Multiple Domains&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Yaml_to_CSV.py&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import csv
import yaml

# creating header for the csv file
fields = {
    'name' : 'Name',
    'ipv4-address' : 'IP',
    'subnet4' : 'Subnet4',
    'subnet-mask' : 'Subnet-Mask',
    'ipv4-address-first' : 'IPv4-Address-First',
    'ipv4-address-last' : 'IPv4-Address-Last',
    'comments' : 'Comments',
    'type' : 'Type',
}

# open fileand write header data to file
with open('Converted_Output.csv', 'w', newline='') as f_output:
    csv_output = csv.DictWriter(f_output, fieldnames=fields.values())
    csv_output.writeheader()

# open log file and key values to file
    for filename in ['tmp/log.yml']:
        with open(filename) as f_input:
            for row_yaml in yaml.safe_load(f_input):
                row_csv = {fields[key] : value for key, value in row_yaml.items()}
                csv_output.writerow(row_csv)

# rember to create a file "Converted_Output.csv"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Finally, your&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- Converted_Output.csv&lt;/FONT&gt;,&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- host,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- login.yml&lt;/FONT&gt;,&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- tmp/log.yml&amp;nbsp; -&amp;gt; a folder "tmp" with a file "log.yml"&lt;BR /&gt;&lt;/FONT&gt;-&amp;nbsp; &lt;FONT color="#FF0000"&gt;playbook&amp;nbsp;&lt;/FONT&gt;(&lt;STRONG&gt;Export_Groups_Host_Network_AddressRange_in_a_Group_to_CSV.yml&lt;/STRONG&gt;) should be in one directory .&lt;BR /&gt;&lt;BR /&gt;You can reach out to me if you are confused or you have more questions&lt;/P&gt;</description>
      <pubDate>Wed, 26 May 2021 17:51:53 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/119496#M5875</guid>
      <dc:creator>ukohae</dc:creator>
      <dc:date>2021-05-26T17:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Listing the members of a network group</title>
      <link>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/119497#M5876</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;If you use ansible. I have a working solution I created&lt;BR /&gt;&lt;STRONG&gt;Export_Groups_Host_Network_AddressRange_in_a_Group_to_CSV.yml&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;Note&lt;/FONT&gt;&lt;/STRONG&gt;:&amp;nbsp;to use&lt;FONT color="#FF0000"&gt; json_query&lt;/FONT&gt;&amp;nbsp;&lt;FONT color="#FF0000"&gt;filter&lt;/FONT&gt; run "&lt;STRONG&gt;pip install jmespath&lt;/STRONG&gt;" on the command line&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;---
- name: Get Hosts, Networks, Subgroups, Address-Range in a Group and  export to CSV 
  hosts: check_point
  connection: httpapi
  gather_facts: False

  # perform your authentication 
  vars_files:
    - 'login.yml'

  tasks:

  # create group, if group exist, do nothing
  - name: if-group-doesn't-exist-create-one
    check_point.mgmt.cp_mgmt_group:
      name: Your_Group
      state: present
    delegate_to: Your_Domain
    ignore_errors: yes

  # grab all the details in the group
  # Note: if we have about 3000 objects 
  # or thousands of objectin a group, becaus of overload
  # then use details_level: standard
  # this will exclude any comments created in a object
  - name: get-details-from-group
    check_point.mgmt.cp_mgmt_group_facts:
      name: Your_Group
      details_level: full
    register: result
    delegate_to: Your_Domain
    ignore_errors: yes

  # apply filter and get only members present in the group
  - name: filter-result-from-group-facts
    set_fact:
      filtered_group_facts: "{{ result['ansible_facts']['group']['members'] }}"
    register: device
    ignore_errors: yes

  # get only address range present in the group using json query filter run "pip install jmespath" on the command line to enable this filter
  - name: get-address-range-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        comments: comments,
        "ipv4-address-first": "ipv4-address-first",
        "ipv4-address-last": "ipv4-address-last",
        name: name
        }
      new_address_range: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_address_range
    debug:
      var: new_address_range 
    no_log: yes
    ignore_errors: yes


  # get only host present in the group using json query filter
  - name: get-hosts-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        comments: comments,
        "ipv4-address": "ipv4-address",
        name: name
        }
      new_host: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_host
    debug:
      var: new_host 
    no_log: yes
    ignore_errors: yes

  # get only network present in the group using json query filter
  - name: get-networks-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        name: name
        "subnet-mask": "subnet-mask"
        subnet4: subnet4,
        comments: comments
        }
      new_network: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_network
    debug:
      var: new_network 
    no_log: yes
    ignore_errors: yes

  # get only subgroup present in the group using json query filter
  - name: get-subgroup-if-present
    vars:
      reduce_query: &amp;gt;-
        [].{
        type: type,
        name: name,
        comments: comments
        }
      new_group: "{{ filtered_group_facts | json_query(reduce_query) }}"
    register: result_group
    debug:
      var: new_group
    no_log: yes
    ignore_errors: yes

  # extract only address range
  - name: get-only-address-range
    set_fact:
      address_range_lists: "{{ result_address_range.new_address_range | rejectattr('ipv4-address-first', 'match', 'None') | flatten }}"
    ignore_errors: yes

  # extract only host if it exist
  - name: get-only-host
    set_fact:
      host_lists: "{{ (result_network.new_network | rejectattr('subnet-mask', 'match', 'None') | flatten) }}"
    ignore_errors: yes

  # extract only network if it exist
  - name: get-only-network
    set_fact:
      network_lists: "{{ result_host.new_host | rejectattr('ipv4-address','match', 'None') | flatten }}"
    ignore_errors: yes

  # extract group if it exist
  - name: get-only-group
    set_fact:
      group_lists: "{{ result_group.new_group | selectattr('type','match', 'group') | flatten }}"
#     group_lists: "{{ result_group.new_group | rejectattr('members','match', 'None') | flatten }}"
    ignore_errors: yes

  # append the list so we can group them
  - name: combine list
    set_fact:
      list_merged: "{{ network_lists + host_lists + group_lists + address_range_lists }}"
    ignore_errors: yes

  # create log files
  - name: copy-file-to-log
    local_action:
      module: copy
      content: "{{ list_merged | to_nice_yaml}}"
      dest: tmp/log.yml
    changed_when: false

#   # run python script to convert yaml to csv
  - name: run-script-to-do-conversion
    script:
      cmd: /usr/bin/python3 ./Yaml_to_CSV.py

# Note to use json_query file run "pip install jmespath" on the command line

# Note: create a diretory folder 'tmp' and create a file 'log.yml' inside the directory "tmp/log.yml"

# We will parse data into log.yml and resuse it in our python script&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;Credentials&lt;BR /&gt;login.yml&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;ansible_user: Enter_Username
ansible_password: Enter_Password
ansible_httpapi_validate_certs: False
ansible_network_os: check_point.mgmt.checkpoint
ansible_python_interpreter: "python"

# Note: Username and Password you use to log into SmartConsole Checkpoint&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;hosts&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;[check_point]
checkpoint ansible_host=Enter_Address_of_Host

[check_point:vars]
ansible_python_interpreter= "python"

[cma]
Domain_1 ansible_host=Enter_Address_of_Host ansible_checkpoint_domain=Domain_1

Domain_2 ansible_host=Enter_Address_of_Host ansible_checkpoint_domain=Domain_2

Domain_3 ansible_host=Enter_Address_of_Host ansible_checkpoint_domain=Domain_3

[cmas:vars]
ansible_python_interpreter= "python"

# Note: use Domain_1, Domain_2, Domain_3, etc. in case of Multiple Domains&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;Yaml_to_CSV.py&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;import csv
import yaml

# creating header for the csv file
fields = {
    'name' : 'Name',
    'ipv4-address' : 'IP',
    'subnet4' : 'Subnet4',
    'subnet-mask' : 'Subnet-Mask',
    'ipv4-address-first' : 'IPv4-Address-First',
    'ipv4-address-last' : 'IPv4-Address-Last',
    'comments' : 'Comments',
    'type' : 'Type',
}

# open fileand write header data to file
with open('Converted_Output.csv', 'w', newline='') as f_output:
    csv_output = csv.DictWriter(f_output, fieldnames=fields.values())
    csv_output.writeheader()

# open log file and key values to file
    for filename in ['tmp/log.yml']:
        with open(filename) as f_input:
            for row_yaml in yaml.safe_load(f_input):
                row_csv = {fields[key] : value for key, value in row_yaml.items()}
                csv_output.writerow(row_csv)

# rember to create a file "Converted_Output.csv"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Finally, your&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- Converted_Output.csv&lt;/FONT&gt;,&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- host,&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- login.yml&lt;/FONT&gt;,&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;- tmp/log.yml&amp;nbsp; -&amp;gt; a folder "tmp" with a file "log.yml"&lt;BR /&gt;&lt;/FONT&gt;-&amp;nbsp; &lt;FONT color="#FF0000"&gt;playbook&amp;nbsp;&lt;/FONT&gt;(&lt;STRONG&gt;Export_Groups_Host_Network_AddressRange_in_a_Group_to_CSV.yml&lt;/STRONG&gt;) should be in one directory .&lt;BR /&gt;&lt;BR /&gt;You can reach out to me if you are confused or you have more questions&lt;/P&gt;</description>
      <pubDate>Wed, 26 May 2021 17:52:37 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/API-CLI-Discussion/Listing-the-members-of-a-network-group/m-p/119497#M5876</guid>
      <dc:creator>ukohae</dc:creator>
      <dc:date>2021-05-26T17:52:37Z</dc:date>
    </item>
  </channel>
</rss>

