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 hostnameandIcon nameandPretty hostnamein RHEL? and the fact thathostname != icon-name.So, for a server the
Icon nameshould probably set tocomputer,computer-vmorcomputer-serverif not alreadyor according the mentioned naming convention to
Since the Ansible
hostnamemodule – Manage hostname is for setting the hostname onlyone is left with a
commandmodule – Execute commands on targets and Defining "changed" since thehostnameExit 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 nameand if no additional Custom facts are implemented.Finally, a minimal example playbook
will result into an output of
If a
skippedtasks is not the desired behavior one could change the condition to