If you're looking to set the hostname for a system using Ansible then look no further. There are two modules that you can use to configure the hostname: hostname and lineinfile. The first module, hostname, is used to set the system's hostname. Per the