Yes, but you must specify each "member" individually in the group.
- name: add-group
cp_mgmt_group:
members:
- host1
- host2
- ..........
- host150
- NewHost1
- NewHost2
name: MyGroup
state: present
If you have an existing group with e.g. 150 objects and want to assign an existing host to this group. There is no "add" only the new member to group. i have a workaround for this but i don't know if this is a nice way to do it in production. here the groups are also much bigger.
- name: Playbook Add Host to Group
hosts: check_point
#connection: httpapi
vars_files:
- my_vars.yml
tasks:
- name: add host
cp_mgmt_host:
ipv4_address: "{{ ip_addr }}"
name: "host_{{ ip_addr }}"
state: present
color: black
- name: Read greoup content
cp_mgmt_group_facts:
name: "{{ group }}"
details_level: standard
register: groupcontent
- name: create group list
set_fact:
memberlist: "{{ memberlist|default([]) + [ item ] }}"
with_items: "{{ groupcontent.ansible_facts.group.members | json_query(jmesquery) }}" #var: jmesquery: "[*].name"
- name: add new host to list
set_fact:
memberlist: "{{ memberlist|default([]) + [ hostname ] }}"
- name: add list 2 the group
cp_mgmt_group:
members: "{{ memberlist }}"
name: "{{ group }}"
state: present
- name: Publish
cp_mgmt_publish:
another way is to use the "cp_mgmt_host" here you can create a host and assign it to a group. this works fine even if the host did not exist before. if the host exists before the script runs but ignores the "groups" and does not assign the host to the group. is it also a bug of the ansible module ?
tasks:
- name: create a host and add to group
cp_mgmt_host:
ipv4_address: "{{ ip_addr }}"
name: "host_{{ ip_addr }}"
groups: "{{ group }}"
state: present
color: black