hi, in the code below, if the host already exist in gTest1A or shows any error of multiple objects with the same IPs exist if a new host is added, I am trying to tell it to ignore existing host or objects with multiple IPs and create the new host with a unique IP into the group gTest2A (gTest105, 10.1.2.5, FWP -Ansible) , it doesn't create the new host gTest105, 10.1.2.5, FWP -Ansible
Note: gTest1A already exist, but gTest2A needs to be created
gTest1A.csv
Name,IP,Comments
gTest101,10.1.2.3,FWP - Test,
gTest102,10.1.2.4, FWP - Fix,
gTest2A.csv
Name,IP,Comments
gTest103,10.1.2.3,FWP - New Comments,
gTest104,10.1.2.4, FWP - New Comments by user,
gTest105,10.1.2.5,FWp - Ansible,
playbook.yml
---
- name: Global Objects
hosts: check_point
connection: httpapi
gather_facts: False
vars_files:
- 'credentials/my_var.yml'
- 'credentials/login.yml'
tasks:
- name: read-csv-file
read_csv:
path: file_reader/gTest2A.csv
key: Name
register: user
- name: add-host-object
check_point.mgmt.cp_mgmt_host:
name: "{{ item.value.Name | quote }}"
ip_address: "{{ item.value.IP | quote }}"
comments: "{{ item.value.Comments }}"
state: present
auto_publish_session: yes
loop: "{{ user.dict | dict2items }}"
ignore_errors: yes
delegate_to: Global
- name: wait for session to be refreshed
wait_for:
timeout: 30
- set_fact:
hosts_in_group: "{{ user.dict | dict2items | map(attribute='key') | list }}"
- name: add-network-group
check_point.mgmt.cp_mgmt_group:
name: gTest2A
comments: "something different"
state: present
members: "{{ hosts_in_group }}"
auto_publish_session: yes
ignore_errors: yes
delegate_to: Global