Skip to content

Commit

Permalink
fix: Ignore ansible_host: ""
Browse files Browse the repository at this point in the history
rhc.insights.ansible_host set to an empty string causes:

- the Ansible host name to be reset in the Inventory by
`insights-client --ansible_host=`;
- a line `ansible_host=` to be put in the config file.

The former is a job of `{state: absent}`. An empty string should not
cause such a desctructive operation. The latter is ignored by the
Client and is equivatent to that line missing.

Consistently with a similar condition of the display_name parameter,
an empty string ansible_host is treated as undefined. It’s the same
behavior as with a null value.
  • Loading branch information
Glutexo authored and ptoscano committed Mar 11, 2024
1 parent f86bc12 commit e12f8df
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ It is `null` by default and will use the system host name if not specified.

Possible values of this variable:

* `null` or an empty value: the ansible host name is not changed.
* `null` or an empty string: the ansible host name is not changed.
* `{state: absent}`: the ansible host name is unset in the insights-client config file and Host Based Inventory (HBI) is updated to use the system host name.
* any other string value: the ansible host name is changed in Host Based Inventory (HBI).

Expand Down
2 changes: 2 additions & 0 deletions tasks/insights-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
when:
- rhc_insights.ansible_host is defined
- not rhc_insights.ansible_host is none
- rhc_insights.ansible_host != ""
- rhc_insights.ansible_host != __rhc_state_absent
- rhc_insights.ansible_host != omit
lineinfile:
Expand All @@ -56,6 +57,7 @@
when:
- rhc_insights.ansible_host is defined
- not rhc_insights.ansible_host is none
- rhc_insights.ansible_host != ""
- rhc_insights.ansible_host != omit
- rhc_insights.ansible_host != __rhc_state_absent
- __insights_ansible_host_exists.changed
Expand Down
11 changes: 11 additions & 0 deletions tests/tests_insights_ansible_host.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@
command:
grep -ixq "^ansible_host=new-host" {{ __rhc_insights_conf }}
changed_when: false
- name: Change ansible host to an empty string (noop)
include_role:
name: linux-system-roles.rhc
vars:
rhc_insights:
ansible_host: ""
remediation: absent
- name: Check ansible_host has not changed in config file
command:
grep -ixq "^ansible_host=new-host" {{ __rhc_insights_conf }}
changed_when: false

- name: Test ansible_host set to an absent value
block:
Expand Down

0 comments on commit e12f8df

Please sign in to comment.