-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete_access_rule.yml
117 lines (106 loc) · 3.13 KB
/
delete_access_rule.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#https://ash-sidhu.blog/2018/11/07/using-ansible-for-automating-tasks-on-checkpoint-firewall/
---
- name: Delete ACL Rule
hosts: ckp
connection: local
gather_facts: no
vars_files:
- ./vars/default_vars.yml
- ./credentials/gaia_credentials.yml
tasks:
- name: Create Web Services API Session
uri:
url: "https://{{ansible_host }}/web_api/login"
method: POST
headers:
Content-Type: "application/json"
body:
user: "{{ GAIA_USERNAME }}"
password: "{{ GAIA_PASSWORD }}"
body_format: json
return_content: yes
validate_certs: False
register: login_output
# - debug:
# var: login_output
- name: Discover existing sessions
uri:
url: "https://{{ansible_host }}/web_api/show-sessions"
method: POST
headers:
Content-Type: "application/json"
X-chkp-sid: "{{ login_output.json.sid }}"
body:
limit: 500
offset: 0
body_format: json
return_content: yes
validate_certs: False
register: sessions_output
# - debug:
# var: sessions_output
- name: Delete existing sessions
uri:
url: "https://{{ansible_host }}/web_api/discard"
method: POST
headers:
Content-Type: "application/json"
X-chkp-sid: "{{ login_output.json.sid }}"
body:
uid: "{{ item.uid}}"
body_format: json
return_content: yes
validate_certs: False
loop: "{{ sessions_output.json.objects }}"
- name: Retrieve Access Rulebase
uri:
url: "https://{{ansible_host }}/web_api/show-access-rulebase"
method: POST
headers:
Content-Type: "application/json"
X-chkp-sid: "{{ login_output.json.sid }}"
body:
limit: 50
offset: 0
name: Network
body_format: json
return_content: yes
validate_certs: False
register: rules_output
- debug:
var: rules_output.json
- name: Delete Access Rule
uri:
url: "https://{{ansible_host }}/web_api/delete-access-rule"
method: POST
headers:
Content-Type: "application/json"
X-chkp-sid: "{{ login_output.json.sid }}"
body:
uid: "{{ item.uid }}"
layer: Network
body_format: json
return_content: yes
validate_certs: False
loop: "{{ rules_output.json.rulebase }}"
when: item.name == acl_to_delete
- name: Publish changes
uri:
url: "https://{{ansible_host }}/web_api/v1.1/publish"
method: POST
headers:
Content-Type: "application/json"
X-chkp-sid: "{{ login_output.json.sid }}"
body_format: raw
body: "{ }"
validate_certs: False
- name: Terminate Web Services API Session
uri:
url: "https://{{ansible_host }}/web_api/logout"
method: POST
headers:
Content-Type: "application/json"
X-chkp-sid: "{{ login_output.json.sid }}"
body_format: raw
body: "{ }"
validate_certs: False