Using Ansible to add hostname to hostname and hosts file
by sysmicuser from LinuxQuestions.org on (#5NWRV)
Hi,
This might be basic but help me please as I need some help.
I am running ansible from build machine giving target machine's IP address and role I want to apply, example below:
Code:ansible-playbook -i 10.281.71.80, main.yaml --private-key=/tmp/azmal0491.abc.int.pem -u azureadmin -e role_name=auto-author -e vm_ip=10.281.71.80What I want is hostname and hosts file like below, no matter I run 1 time or 10K times Ansible should should have last line or entry in each of these files as like below
Prototype
Code:cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
<Private IP of VM> <Fully Qualified Domain Name> <Hostname>
cat /etc/hostname
<Fully Qualified Domain name>Example
Code:cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.281.71.80 azmal0491.abc.int azmal0491
cat /etc/hostname
azmal0491.abc.intWhat I do know is I get this information if I run the below Linux commands on remote host
Code:hostname -f
azmal0491.abc.int
hostname -I
10.281.71.80
hostname -s
azmal0491I am wondering how to make it all hang together to apply it via Ansible?
Any guidance shall be most sincerely appreciated.
This might be basic but help me please as I need some help.
I am running ansible from build machine giving target machine's IP address and role I want to apply, example below:
Code:ansible-playbook -i 10.281.71.80, main.yaml --private-key=/tmp/azmal0491.abc.int.pem -u azureadmin -e role_name=auto-author -e vm_ip=10.281.71.80What I want is hostname and hosts file like below, no matter I run 1 time or 10K times Ansible should should have last line or entry in each of these files as like below
Prototype
Code:cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
<Private IP of VM> <Fully Qualified Domain Name> <Hostname>
cat /etc/hostname
<Fully Qualified Domain name>Example
Code:cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.281.71.80 azmal0491.abc.int azmal0491
cat /etc/hostname
azmal0491.abc.intWhat I do know is I get this information if I run the below Linux commands on remote host
Code:hostname -f
azmal0491.abc.int
hostname -I
10.281.71.80
hostname -s
azmal0491I am wondering how to make it all hang together to apply it via Ansible?
Any guidance shall be most sincerely appreciated.