From e12f8df4ba2dd4d457122147e84d402e0be9e01d Mon Sep 17 00:00:00 2001 From: Glutexo Date: Thu, 29 Feb 2024 15:27:28 +0100 Subject: [PATCH] fix: Ignore ansible_host: "" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- README.md | 2 +- tasks/insights-client.yml | 2 ++ tests/tests_insights_ansible_host.yml | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d12a548..6812527 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/tasks/insights-client.yml b/tasks/insights-client.yml index 299bcbd..2c44120 100644 --- a/tasks/insights-client.yml +++ b/tasks/insights-client.yml @@ -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: @@ -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 diff --git a/tests/tests_insights_ansible_host.yml b/tests/tests_insights_ansible_host.yml index 68cab6e..655901f 100644 --- a/tests/tests_insights_ansible_host.yml +++ b/tests/tests_insights_ansible_host.yml @@ -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: