Red Hat has a command called hostnamectl set-icon-name
. Is it correct to configure this using Ansible?
The usual command
ansible.builtin.shell: "hostnamectl set-icon-name {{ inventory_hostname }}"
is possible, of course, but with each pass the Ansible thinks that it is changing this parameter, which is not good.
That's right. It is usually used in order to Changing a hostname. See also
hostnamectl
— Control the system hostname.Plase take note about What is different between
Static hostname
andIcon name
andPretty hostname
in RHEL? and the fact thathostname != icon-name
.So, for a server the
Icon name
should probably set tocomputer
,computer-vm
orcomputer-server
if not alreadyor according the mentioned naming convention to
Since the Ansible
hostname
module – Manage hostname is for setting the hostname onlyone is left with a
command
module – Execute commands on targets and Defining "changed" since thehostname
Exit status will be just beand in order to gain Idempotency. This is also due to the fact that Ansible facts do not gather the
Icon name
and if no additional Custom facts are implemented.Finally, a minimal example playbook
will result into an output of
If a
skipped
tasks is not the desired behavior one could change the condition to