I want to change my remote server's hostname so I used the hostname module:
- hostname: name="{{my_hostname}}" But that also changed the ansible_host to that value, and so messed up remaining tasks.
When I did it manually:
- shell: hostnamectl set-hostname {{my_hostname}} Then the remote server's hostname was changed, AND the ansible_host global var wasn't changed, and all remaining plays completed successfully.
Am I using the hostname module correctly? I have a feeling it doesn't do what I think.
(I also noticed lots of bug reports in the repo, but I'm not sure if they're related to what I'm doing as I'm not using cloud-init).
ansible_host?ansible_hostcomes from the hosts inventory file, as one of those built-in variables? Regardless, is the code above supposed to work, or did I use the wrong module?ansible_hostcomes from the host's own hostname. It can be wrong, which is presumably why you are changing it! The inventory hostname is stored ininventory_hostname. Most of the time,inventory_hostnameis what you want to use in your own playbooks to refer to your hosts.hostnamemodule do what I think it does - change the hostname of the remote server?hostname:module changes the target host's hostname. It doesn't have to be remote, it can be used on the local system (ansible controller) as well.