Open gardar opened 2 years ago
As a dirty workaround it's possible to check the registered output and only mark the task as changed when there's difference in the diff outputs. This does however not completely fix the issue, as the ansible roles of the hostgroup are not printed in the diff output.
- name: "Create hostgroups"
theforeman.foreman.hostgroup:
server_url: "{{ lookup('env', 'SATELLITE_SERVER_URL') }}"
username: "{{ lookup('env', 'SATELLITE_USERNAME') }}"
password: "{{ lookup('env', 'SATELLITE_PASSWORD') }}"
validate_certs: "{{ lookup('env', 'SATELLITE_VALIDATE_CERTS') }}"
name: "{{ item.name }}"
ansible_roles: "{{ item.ansible_roles }}"
description: "{{ item.description }}"
subnet: "{{ item.subnet }}"
delegate_to: localhost
register: created
loop: "{{ hostgroups }}"
vars:
hostgroups:
- name: mygroup
description: mydesc
subnet: mysubnet
ansible_roles:
- role1
changed_when:
- (created.diff.before.hostgroups[0].keys() | symmetric_difference(created.diff.after.hostgroups[0].keys()))
- (created.diff.before.hostgroups[0].values() | symmetric_difference(created.diff.after.hostgroups[0].values()))
SUMMARY
Adding the
ansible_roles
parameter to the hostgroup module gives achanged
status on each run which makes it no longer idempotent. And to add to the confusion if you register the output you will not see any changes in the diff, the before and after are exactly the same as the ansible roles aren't displayed in the diff output.ISSUE TYPE
ANSIBLE VERSION
COLLECTION VERSION
KATELLO/FOREMAN VERSION
STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS