Description
Summary
The module 'ipa_hostgroup' documents that its 'state' parameter accepts 4 values: 'absent', 'disabled', 'enabled', and 'present'.
However, when 'disabled' or 'enabled' is passed in, the hostgroup does not get created. (In fact, the hostgroup gets deleted if it exists!)
Looking at the code in this repository, it is obvious: in the 'ensure' function, the code only checks "if state == 'present'" around line 163; when 'enabled' or 'disabled' is passed in, the "delete hostgroup" if branch gets taken! (In the similar ipa_hbacrule module, the test at the equivalent point in code is a membership test - "if state in ['present', 'enabled', 'disabled']
It seems to me that hostgroups are not something that are enabled or disabled, so it is possible the correct action is to not accept those values. However, I realize that could create version compatibility issues; if it does accept 'enabled' and 'disabled', , then an enabled or disabled hostgroup should probably get created!
Issue Type
Bug Report
Component Name
ipa_hostgroup
Ansible Version
$ ansible --version
ansible [core 2.14.2]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/var/paas/tmp/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3.11/site-packages/ansible
ansible collection location = /var/paas/tmp/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.11.5 (main, Sep 22 2023, 15:34:29) [GCC 8.5.0 20210514 (Red Hat 8.5.0-20)] (/usr/bin/python3.11)
jinja version = 3.1.2
libyaml = True
Community.general Version
$ ansible-galaxy collection list community.general
# /usr/share/ansible/collections/ansible_collections
Collection Version
----------------- -------
community.general 6.5.0
Configuration
$ ansible-config dump --only-changed
OS / Environment
RHEL 8
Steps to Reproduce
---
- hosts: all
gather_facts: false
tasks:
- ipa_hostgroup:
# 'present' works.
# 'enabled' and 'disabled' behave equivalent to 'absent'
state: 'enabled'
name: 'testhostgroup'
# adjust for your environment!
ipa_host: '{{ ipa.fqdn }}'
ipa_user: 'admin'
ipa_pass: '{{ pwd_content.admin_pass }}'
Expected Results
When I ran the playbook shown above, I expected the hostgroup to get created. It did not. "ipa hostgroup-find testhostgroup" returned zero results.
When I changed the playbook to use state='present', the hostgroup was created as expected.
When I changed it back to 'enabled' and ran it again, the hostgroup I had just created with 'present' was deleted! I certainly did not expect that!
Actual Results
Code of Conduct
- I agree to follow the Ansible Code of Conduct