Hi, I hope I can ask my question in this post and don't need to create a new post for this since my question is also related to Check Point automation with Ansible.
Due to FQDN resolving issues on our current version (and not able to upgrade to R80 yet since we are using SP solution) we want to update our FW rulebase based doing some DNS queries in a script and create new host objects and update a network object group with the relevant host objects). Since there's still an issue with the way the cpAnsible module is working (idempotence - https://github.com/CheckPointSW/cpAnsible/issues/7) I would like to use the parameter set-if-exists but for some reason my ansible playbook if failing with the following error: "The error was: ValueError: No JSON object could be decoded".
So basically I'm using the set-if-exists parameter wrong in my playbook. If I remove this line the playbook will run successfully (for new/not yet configured host objects)
PLAY [localhost] *******************************************************************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************************************************************************
ok: [localhost]
TASK [login] ***********************************************************************************************************************************************************************
ok: [localhost]
TASK [add host] ********************************************************************************************************************************************************************
changed: [localhost] => (item={u'ip_address': u'172.217.23.206', u'fqdn': u'<a href="http://www.youtube.com" target="_blank">www.youtube.com</a>', u'name': u'fqdn-<a href="http://www.youtube.com-172.217.23.206" target="_blank">www.youtube.com-172.217.23.206</a>', u'host_name': u'fqdn-<a href="http://www.youtube.com-172.217.23.206" target="_blank">www.youtube.com-172.217.23.206</a>'})
changed: [localhost] => (item={u'ip_address': u'172.217.23.238', u'fqdn': u'<a href="http://www.youtube.com" target="_blank">www.youtube.com</a>', u'name': u'fqdn-<a href="http://www.youtube.com-172.217.23.238" target="_blank">www.youtube.com-172.217.23.238</a>', u'host_name': u'fqdn-<a href="http://www.youtube.com-172.217.23.238" target="_blank">www.youtube.com-172.217.23.238</a>'})
changed: [localhost] => (item={u'ip_address': u'216.58.201.78', u'fqdn': u'<a href="http://www.youtube.com" target="_blank">www.youtube.com</a>', u'name': u'fqdn-<a href="http://www.youtube.com-216.58.201.78" target="_blank">www.youtube.com-216.58.201.78</a>', u'host_name': u'fqdn-<a href="http://www.youtube.com-216.58.201.78" target="_blank">www.youtube.com-216.58.201.78</a>'})
TASK [publish] *********************************************************************************************************************************************************************
ok: [localhost]
TASK [logout] **********************************************************************************************************************************************************************
ok: [localhost]
PLAY RECAP *************************************************************************************************************************************************************************
localhost : ok=5 changed=1 unreachable=0 failed=0
My playbook looks like this:
---
- hosts: "localhost" # Note #2 in the Description section
vars_files:
- test.yml
tasks:
- name: "login" # You have to login to the management
# server before running any commands
check_point_mgmt:
command: login
parameters:
username: "{{username}}" # Variables set in /etc/ansible/hosts, to avoid needing
password: "{{password}}" # to type your login details in every playbook.
management: "{{mds_ip}}"
domain: "{{mds_domain}}"
fingerprint: "{{mds_fingerprint}}"
register: login_response # Register the output from the login
# command so we can use it later to run commands.
- name: "add host"
check_point_mgmt:
command: add-host # Name of the command
parameters: # The parameters for it, in dictionary form
name: "{{item.host_name}}"
ip-address: "{{item.ip_address}}"
set-if-exists: true
session-data: "{{ login_response }}" # The session data we received from
with_items: "{{host_table}}"
- name: "publish" # Publishing is important if you want
# your changes to be saved.
check_point_mgmt: # This will actually 'discard' when
# check mode is enabled (ansible-playbook -C)
# unless you add 'always_run: yes' to the task.
command: publish
session-data: "{{login_response}}"
- name: logout
check_point_mgmt:
command: logout
session-data: '{{login_response}}'
Many thanks!