Chapter 19. Managing host groups using Ansible playbooks
Organize IdM hosts into groups using Ansible to simplify the application of access control policies and other configurations.
19.1. Host groups in IdM Copy linkLink copied to clipboard!
Understand how IdM host groups centralize control over access policies and other management tasks for sets of hosts with common characteristics. For example, you can define host groups based on company departments, physical locations, or access control requirements.
A host group in IdM can include:
- IdM servers and clients
Other IdM host groups
- Host groups created by default
-
By default, the IdM server creates the host group
ipaserversfor all IdM server hosts. - Direct and indirect group members
- Group attributes in IdM apply to both direct and indirect members: when host group B is a member of host group A, all members of host group B are considered indirect members of host group A.
19.2. Ensuring the presence of IdM host groups using Ansible playbooks Copy linkLink copied to clipboard!
Create Identity Management (IdM) host groups using Ansible to organize hosts for simplified access control and policy management.
Without Ansible, host group entries are created in IdM using the ipa hostgroup-add command. The result of adding a host group to IdM is the state of the host group being present in IdM. Because of the Ansible reliance on idempotence, to add a host group to IdM using Ansible, you must create a playbook in which you define the state of the host group as present: state: present.
Prerequisites
You have configured your Ansible control node to meet the following requirements:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica.
Procedure
Create an Ansible playbook file with the necessary host group information. To simplify the procedure, you can copy and modify the example in the
/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/user/ensure-hostgroup-is-present.ymlfile.Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the playbook, state: present signifies a request to add the host group to IdM unless it already exists there.
Run the playbook:
ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hostgroup-is-present.yml
$ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hostgroup-is-present.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Log into
ipaserverasadmin:ssh admin@server.idm.example.com Password: [admin@server /]$
$ ssh admin@server.idm.example.com Password: [admin@server /]$Copy to Clipboard Copied! Toggle word wrap Toggle overflow Request a Kerberos ticket for
admin:kinit admin Password for admin@IDM.EXAMPLE.COM:
$ kinit admin Password for admin@IDM.EXAMPLE.COM:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display information about the host group whose presence in IdM you wanted to ensure:
ipa hostgroup-show databases Host-group: databases
$ ipa hostgroup-show databases Host-group: databasesCopy to Clipboard Copied! Toggle word wrap Toggle overflow
The databases host group exists in IdM.
19.3. Ensuring the presence of hosts in IdM host groups using Ansible playbooks Copy linkLink copied to clipboard!
Add hosts to Identity Management (IdM) host groups using Ansible to organize systems for access control and policy application.
Prerequisites
You have configured your Ansible control node to meet the following requirements:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica. - The hosts you want to reference in your Ansible playbook exist in IdM. For details, see Ensuring the presence of an IdM host entry using Ansible playbooks.
- The host groups you reference from the Ansible playbook file have been added to IdM. For details, see Ensuring the presence of IdM host groups using Ansible playbooks.
Procedure
Create an Ansible playbook file with the necessary host information:
-
Specify the name of the host group using the
namevariable of thefreeipa.ansible_freeipa.ipahostgroupmodule. -
Specify the name of the host with the
hostvariable of thefreeipa.ansible_freeipa.ipahostgroupmodule.
To simplify the procedure, you can copy and modify the examples in the
/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/hostgroup/ensure-hosts-and-hostgroups-are-present-in-hostgroup.ymlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This playbook adds the db.idm.example.com host to the databases host group. The
action: memberline indicates that when the playbook is run, no attempt is made to add the databases group itself. Instead, only an attempt is made to add db.idm.example.com to databases.-
Specify the name of the host group using the
Run the playbook:
ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hosts-or-hostgroups-are-present-in-hostgroup.yml
$ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hosts-or-hostgroups-are-present-in-hostgroup.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Log into
ipaserverasadmin:ssh admin@server.idm.example.com Password: [admin@server /]$
$ ssh admin@server.idm.example.com Password: [admin@server /]$Copy to Clipboard Copied! Toggle word wrap Toggle overflow Request a Kerberos ticket for
admin:kinit admin Password for admin@IDM.EXAMPLE.COM:
$ kinit admin Password for admin@IDM.EXAMPLE.COM:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display information about a host group to see which hosts are present in it:
ipa hostgroup-show databases Host-group: databases Member hosts: db.idm.example.com
$ ipa hostgroup-show databases Host-group: databases Member hosts: db.idm.example.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow
The db.idm.example.com host is present as a member of the databases host group.
19.4. Nesting IdM host groups using Ansible playbooks Copy linkLink copied to clipboard!
Nest host groups within parent groups in Identity Management (IdM) using Ansible to organize hosts into logical hierarchies.
Prerequisites
You have configured your Ansible control node to meet the following requirements:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica. - The host groups you reference from the Ansible playbook file exist in IdM. For details, see Ensuring the presence of IdM host groups using Ansible playbooks.
Procedure
Create an Ansible playbook file with the necessary host group information:
-
To ensure that a nested host group A exists in a host group B: in the Ansible playbook, specify, among the variables of the
freeipa.ansible_freeipa.ipahostgrouptask, the name of the host group B using thenamevariable. -
Specify the name of the nested hostgroup A with the
hostgroupvariable.
To simplify this step, you can copy and modify the examples in the
/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/hostgroup/ensure-hosts-and-hostgroups-are-present-in-hostgroup.ymlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This Ansible playbook ensures the presence of the myqsl-server and oracle-server host groups in the databases host group. The
action: memberline indicates that when the playbook is run, no attempt is made to add the databases group itself to IdM.-
To ensure that a nested host group A exists in a host group B: in the Ansible playbook, specify, among the variables of the
Run the playbook:
ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hosts-or-hostgroups-are-present-in-hostgroup.yml
$ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hosts-or-hostgroups-are-present-in-hostgroup.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Log into
ipaserverasadmin:ssh admin@server.idm.example.com Password: [admin@server /]$
$ ssh admin@server.idm.example.com Password: [admin@server /]$Copy to Clipboard Copied! Toggle word wrap Toggle overflow Request a Kerberos ticket for
admin:kinit admin Password for admin@IDM.EXAMPLE.COM:
$ kinit admin Password for admin@IDM.EXAMPLE.COM:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display information about the host group in which nested host groups are present:
ipa hostgroup-show databases Host-group: databases Member hosts: db.idm.example.com Member host-groups: mysql-server, oracle-server
$ ipa hostgroup-show databases Host-group: databases Member hosts: db.idm.example.com Member host-groups: mysql-server, oracle-serverCopy to Clipboard Copied! Toggle word wrap Toggle overflow
The mysql-server and oracle-server host groups exist in the databases host group.
19.5. Ensuring the presence of member managers in IdM host groups using Ansible playbooks Copy linkLink copied to clipboard!
Delegate host group membership management to specific users or groups in Identity Management (IdM), allowing them to add and remove hosts.
Prerequisites
On the control node:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica. - You must have the name of the host or host group you are adding as member managers and the name of the host group you want them to manage.
Procedure
Create an Ansible playbook file with the necessary host and host group member management information:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the playbook:
ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/add-member-managers-host-groups.yml
$ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/add-member-managers-host-groups.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
You can verify if the group_name group contains example_member and project_admins as member managers by using the ipa group-show command:
Log into
ipaserveras administrator:ssh admin@server.idm.example.com Password: [admin@server /]$
$ ssh admin@server.idm.example.com Password: [admin@server /]$Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display information about testhostgroup:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
19.6. Ensuring the absence of hosts from IdM host groups using Ansible playbooks Copy linkLink copied to clipboard!
Remove hosts from Identity Management (IdM) host groups using Ansible when reorganizing group membership or decommissioning systems.
Prerequisites
You have configured your Ansible control node to meet the following requirements:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica. - The hosts you want to reference in your Ansible playbook exist in IdM. For details, see Ensuring the presence of an IdM host entry using Ansible playbooks.
- The host groups you reference from the Ansible playbook file exist in IdM. For details, see Ensuring the presence of IdM host groups using Ansible playbooks.
Procedure
Create an Ansible playbook file with the necessary host and host group information:
-
Specify the name of the host group using the
namevariable of thefreeipa.ansible_freeipa.ipahostgroupmodule. -
Specify the name of the host whose absence from the host group you want to ensure using the
hostvariable of thefreeipa.ansible_freeipa.ipahostgroupmodule.
To simplify the procedure, you can copy and modify the examples in the
/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/hostgroup/ensure-hosts-and-hostgroups-are-absent-in-hostgroup.ymlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This playbook ensures the absence of the db.idm.example.com host from the databases host group. The action: member line indicates that when the playbook is run, no attempt is made to remove the databases group itself.
-
Specify the name of the host group using the
Run the playbook:
ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hosts-or-hostgroups-are-absent-in-hostgroup.yml
$ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hosts-or-hostgroups-are-absent-in-hostgroup.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Log into
ipaserverasadmin:ssh admin@server.idm.example.com Password: [admin@server /]$
$ ssh admin@server.idm.example.com Password: [admin@server /]$Copy to Clipboard Copied! Toggle word wrap Toggle overflow Request a Kerberos ticket for
admin:kinit admin Password for admin@IDM.EXAMPLE.COM:
$ kinit admin Password for admin@IDM.EXAMPLE.COM:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display information about the host group and the hosts it contains:
ipa hostgroup-show databases Host-group: databases Member host-groups: mysql-server, oracle-server
$ ipa hostgroup-show databases Host-group: databases Member host-groups: mysql-server, oracle-serverCopy to Clipboard Copied! Toggle word wrap Toggle overflow
The db.idm.example.com host does not exist in the databases host group.
19.7. Ensuring the absence of nested host groups from IdM host groups using Ansible playbooks Copy linkLink copied to clipboard!
Remove nested host groups from parent groups in Identity Management (IdM) using Ansible when restructuring your host group hierarchy.
Prerequisites
You have configured your Ansible control node to meet the following requirements:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica. - The host groups you reference from the Ansible playbook file exist in IdM. For details, see Ensuring the presence of IdM host groups using Ansible playbooks.
Procedure
Create an Ansible playbook file with the necessary host group information:
-
Specify, among the
freeipa.ansible_freeipa.ipahostgroupvariables, the name of the outer host group using thenamevariable. -
Specify the name of the nested hostgroup with the
hostgroupvariable.
To simplify this step, you can copy and modify the examples in the
/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/hostgroup/ensure-hosts-and-hostgroups-are-absent-in-hostgroup.ymlfile:Copy to Clipboard Copied! Toggle word wrap Toggle overflow This playbook makes sure that the mysql-server and oracle-server host groups are absent from the databases host group. The
action: memberline indicates that when the playbook is run, no attempt is made to ensure the databases group itself is deleted from IdM.-
Specify, among the
Run the playbook:
ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hosts-or-hostgroups-are-absent-in-hostgroup.yml
$ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hosts-or-hostgroups-are-absent-in-hostgroup.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Log into
ipaserveras admin:ssh admin@server.idm.example.com Password: [admin@server /]$
$ ssh admin@server.idm.example.com Password: [admin@server /]$Copy to Clipboard Copied! Toggle word wrap Toggle overflow Request a Kerberos ticket for admin:
kinit admin Password for admin@IDM.EXAMPLE.COM:
$ kinit admin Password for admin@IDM.EXAMPLE.COM:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display information about the host group from which nested host groups should be absent:
ipa hostgroup-show databases Host-group: databases
$ ipa hostgroup-show databases Host-group: databasesCopy to Clipboard Copied! Toggle word wrap Toggle overflow
The output confirms that the mysql-server and oracle-server nested host groups are absent from the outer databases host group.
19.8. Ensuring the absence of IdM host groups using Ansible playbooks Copy linkLink copied to clipboard!
Delete Identity Management (IdM) host groups using Ansible when consolidating groups or removing obsolete groupings from your domain.
Without Ansible, host group entries are removed from IdM using the ipa hostgroup-del command. The result of removing a host group from IdM is the state of the host group being absent from IdM. Because of the Ansible reliance on idempotence, to remove a host group from IdM using Ansible, you must create a playbook in which you define the state of the host group as absent: state: absent.
Prerequisites
You have configured your Ansible control node to meet the following requirements:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica.
Procedure
Create an Ansible playbook file with the necessary host group information. To simplify this step, you can copy and modify the example in the
/usr/share/ansible/collections/ansible_collections/freeipa/ansible_freeipa/playbooks/user/ensure-hostgroup-is-absent.ymlfile.Copy to Clipboard Copied! Toggle word wrap Toggle overflow This playbook ensures the absence of the databases host group from IdM. The
state: absentmeans a request to delete the host group from IdM unless it is already deleted.Run the playbook:
ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hostgroup-is-absent.yml
$ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-hostgroup-is-absent.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Log into
ipaserverasadmin:ssh admin@server.idm.example.com Password: [admin@server /]$
$ ssh admin@server.idm.example.com Password: [admin@server /]$Copy to Clipboard Copied! Toggle word wrap Toggle overflow Request a Kerberos ticket for
admin:kinit admin Password for admin@IDM.EXAMPLE.COM:
$ kinit admin Password for admin@IDM.EXAMPLE.COM:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display information about the host group whose absence you ensured:
ipa hostgroup-show databases ipa: ERROR: databases: host group not found
$ ipa hostgroup-show databases ipa: ERROR: databases: host group not foundCopy to Clipboard Copied! Toggle word wrap Toggle overflow
The databases host group does not exist in IdM.
19.9. Ensuring the absence of member managers from IdM host groups using Ansible playbooks Copy linkLink copied to clipboard!
Remove member manager privileges from users or groups for Identity Management (IdM) host groups when revoking delegated management responsibilities.
Prerequisites
On the control node:
- You are using Ansible version 2.15 or later.
-
You have installed the
ansible-freeipapackage. - The example assumes that in the ~/MyPlaybooks/ directory, you have created an Ansible inventory file with the fully-qualified domain name (FQDN) of the IdM server.
-
The example assumes that the secret.yml Ansible vault stores your
ipaadmin_passwordand that you have access to a file that stores the password protecting the secret.yml file.
-
The target node, that is the node on which the
freeipa.ansible_freeipamodule is executed, is part of the IdM domain as an IdM client, server or replica. - You must have the name of the user or user group you are removing as member managers and the name of the host group they are managing.
Procedure
Create an Ansible playbook file with the necessary host and host group member management information:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the playbook:
ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-member-managers-host-groups-are-absent.yml
$ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-member-managers-host-groups-are-absent.ymlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
You can verify if the group_name group does not contain example_member or project_admins as member managers by using the ipa group-show command:
Log into
ipaserveras administrator:ssh admin@server.idm.example.com Password: [admin@server /]$
$ ssh admin@server.idm.example.com Password: [admin@server /]$Copy to Clipboard Copied! Toggle word wrap Toggle overflow Display information about testhostgroup:
ipaserver]$ ipa hostgroup-show group_name Host-group: group_name Member hosts: server.idm.example.com Member host-groups: testhostgroup2
ipaserver]$ ipa hostgroup-show group_name Host-group: group_name Member hosts: server.idm.example.com Member host-groups: testhostgroup2Copy to Clipboard Copied! Toggle word wrap Toggle overflow