Chapter 14. Ensuring the presence of IdM groups and group members using Ansible playbooks

The following procedure describes ensuring the presence of IdM groups and group members - both users and user groups - using an Ansible playbook.



  1. Create an inventory file, for example inventory.file, and define ipaserver in it:

  2. Create an Ansible playbook file with the necessary user and group information. To simplify this step, you can copy and modify the examples in the /usr/share/doc/ansible-freeipa/playbooks/user/ directory. For example, to ensure the presence of groups named ops, sysops and appops, the presence of a user named idm_user in sysops, and the presence of the sysops and appops groups in ops, you can combine the add-group.yml and add-groups-to-group.yml playbooks into a new playbook:

    - name: Playbook to handle groups
      hosts: ipaserver
      become: true
      - name: Create group ops with gid 1234
          ipaadmin_password: Secret123
          name: ops
          gidnumber: 1234
      - name: Create group sysops
          ipaadmin_password: Secret123
          name: sysops
          - idm_user
      - name: Create group appops
          ipaadmin_password: Secret123
          name: appops
      - name: Add group members sysops and appops to group ops
          ipaadmin_password: Secret123
          name: ops
          - sysops
          - appops
  3. Run the playbook:

    $ ansible-playbook -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/add-group-members.yml

Verification steps

You can verify if the ops group contains sysops and appops as direct members and idm_user as an indirect member by using the ipa group-show command:

  1. Log into ipaserver as administrator:

    $ ssh
    [admin@server /]$
  2. Display information about ops:

    ipaserver]$ ipa group-show ops
      Group name: ops
      GID: 1234
      Member groups: sysops, appops
      Indirect Member users: idm_user

    The appops and sysops groups - the latter including the idm_user user - exist in IdM.

Additional resources

  • For more information about ensuring the presence of user groups using Ansible, see the /usr/share/doc/ansible-freeipa/ Markdown file.