<?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 Create role to add sections and rules in Ansible</title>
    <link>https://community.checkpoint.com/t5/Ansible/Create-role-to-add-sections-and-rules/m-p/142602#M648</link>
    <description>&lt;P&gt;Hi there!&lt;/P&gt;&lt;P&gt;I want to create a access layer ruleset with sections and rules.&lt;/P&gt;&lt;P&gt;There are two modules provided by checkpoint which seem to be relevant:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://docs.ansible.com/ansible/latest/collections/check_point/mgmt/cp_mgmt_access_rule_module.html#ansible-collections-check-point-mgmt-cp-mgmt-access-rule-module" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;cp_mgmt_access_rule&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://docs.ansible.com/ansible/latest/collections/check_point/mgmt/cp_mgmt_access_section_module.html#ansible-collections-check-point-mgmt-cp-mgmt-access-section-module" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;cp_mgmt_access_section&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN class=""&gt;I am having a yaml file which contains all rules in the right order, looking something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;-
    Name: "FW MGMT"
    Comments: "MGMT Clients to FW"
    Action: Accept
    Destination: o-fw01
    Source: allow_fwmgmt
    Enable: yes
    Service:
      - ssh_version_2
      - https-tcp8443
-
    Name: "GW Identity Access"
    Comments: "Access f. Identity Awareness"
    Action: Accept
    Destination: fw01
    Source: allow_fw-identity
    Enable: yes
    Service: https
-
    Name: "FW Stealth"
    Comments: "FW Stealth Rule"
    Action: Drop
    Destination: fw01
    Source: Any
    Enable: yes
    Service: Any&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The corresponding task looks something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;- name: set access rule
  check_point.mgmt.cp_mgmt_access_rule:
    name: "{{ item.Name }}"
    position: "{{ index | int + 1 }}"
    comments: "{{ item.Comments }}"
    destination: "{{ item.Destination }}"
    source: "{{ item.Source }}"
    service: "{{ item.Service }}"
    action: "{{ item.Action }}"
  loop: "{{ cp_access_rules }}"
  loop_control:
    index_var: index&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; So it takes the first entry of the rules file and submits it as first rule to the rulebase, takes the second on and puts it on second position and so on, using the index.&lt;/P&gt;&lt;P&gt;Is it somehow possible to combine this with sections?&lt;/P&gt;&lt;P&gt;Is it possible to put sections between the rules in the same file and let ansible decide which task to execute?&lt;/P&gt;&lt;P&gt;I tried put a&amp;nbsp;cp_mgmt_access_rule and a&amp;nbsp;cp_mgmt_access_section in a block and loop the block but ansible does not support looping entire blocks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a better way to do this?&lt;/P&gt;</description>
    <pubDate>Mon, 28 Feb 2022 10:21:21 GMT</pubDate>
    <dc:creator>User1234</dc:creator>
    <dc:date>2022-02-28T10:21:21Z</dc:date>
    <item>
      <title>Create role to add sections and rules</title>
      <link>https://community.checkpoint.com/t5/Ansible/Create-role-to-add-sections-and-rules/m-p/142602#M648</link>
      <description>&lt;P&gt;Hi there!&lt;/P&gt;&lt;P&gt;I want to create a access layer ruleset with sections and rules.&lt;/P&gt;&lt;P&gt;There are two modules provided by checkpoint which seem to be relevant:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://docs.ansible.com/ansible/latest/collections/check_point/mgmt/cp_mgmt_access_rule_module.html#ansible-collections-check-point-mgmt-cp-mgmt-access-rule-module" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;cp_mgmt_access_rule&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://docs.ansible.com/ansible/latest/collections/check_point/mgmt/cp_mgmt_access_section_module.html#ansible-collections-check-point-mgmt-cp-mgmt-access-section-module" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;cp_mgmt_access_section&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN class=""&gt;I am having a yaml file which contains all rules in the right order, looking something like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;-
    Name: "FW MGMT"
    Comments: "MGMT Clients to FW"
    Action: Accept
    Destination: o-fw01
    Source: allow_fwmgmt
    Enable: yes
    Service:
      - ssh_version_2
      - https-tcp8443
-
    Name: "GW Identity Access"
    Comments: "Access f. Identity Awareness"
    Action: Accept
    Destination: fw01
    Source: allow_fw-identity
    Enable: yes
    Service: https
-
    Name: "FW Stealth"
    Comments: "FW Stealth Rule"
    Action: Drop
    Destination: fw01
    Source: Any
    Enable: yes
    Service: Any&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The corresponding task looks something like this:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;- name: set access rule
  check_point.mgmt.cp_mgmt_access_rule:
    name: "{{ item.Name }}"
    position: "{{ index | int + 1 }}"
    comments: "{{ item.Comments }}"
    destination: "{{ item.Destination }}"
    source: "{{ item.Source }}"
    service: "{{ item.Service }}"
    action: "{{ item.Action }}"
  loop: "{{ cp_access_rules }}"
  loop_control:
    index_var: index&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; So it takes the first entry of the rules file and submits it as first rule to the rulebase, takes the second on and puts it on second position and so on, using the index.&lt;/P&gt;&lt;P&gt;Is it somehow possible to combine this with sections?&lt;/P&gt;&lt;P&gt;Is it possible to put sections between the rules in the same file and let ansible decide which task to execute?&lt;/P&gt;&lt;P&gt;I tried put a&amp;nbsp;cp_mgmt_access_rule and a&amp;nbsp;cp_mgmt_access_section in a block and loop the block but ansible does not support looping entire blocks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a better way to do this?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Feb 2022 10:21:21 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Ansible/Create-role-to-add-sections-and-rules/m-p/142602#M648</guid>
      <dc:creator>User1234</dc:creator>
      <dc:date>2022-02-28T10:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create role to add sections and rules</title>
      <link>https://community.checkpoint.com/t5/Ansible/Create-role-to-add-sections-and-rules/m-p/142809#M650</link>
      <description>&lt;P&gt;Sounds like more of a question of whether Ansible will allow this sort of functionality versus a specific question with our module.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 15:25:30 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Ansible/Create-role-to-add-sections-and-rules/m-p/142809#M650</guid>
      <dc:creator>PhoneBoy</dc:creator>
      <dc:date>2022-03-02T15:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create role to add sections and rules</title>
      <link>https://community.checkpoint.com/t5/Ansible/Create-role-to-add-sections-and-rules/m-p/142826#M651</link>
      <description>&lt;P&gt;No it is not possible. Push your rules, then push your sections after that. It's going to be position specific. What you can do is know your rules around a section and store that as&amp;nbsp;&lt;EM&gt;set_facts&lt;/EM&gt; and reuse that variable in setting the position.&lt;BR /&gt;Good luck!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Mar 2022 17:23:17 GMT</pubDate>
      <guid>https://community.checkpoint.com/t5/Ansible/Create-role-to-add-sections-and-rules/m-p/142826#M651</guid>
      <dc:creator>Art_Zalenekas</dc:creator>
      <dc:date>2022-03-02T17:23:17Z</dc:date>
    </item>
  </channel>
</rss>

