On Thursday, January 24, 2019 at 8:10:47 PM UTC+5:30, Pradeep Ghorpade 
wrote:
>
> Hello Team,
>
> I am looking ansible playbook which will update host file in below 
> scenario.
>
> I have 2 group server both are aws instance.
> [test]
> xyz
>
> [test1]
> abc
>
> I want to update host file on test group server(xyz) with test1 
> server(abc) details like ip address and hostname.
>
> I dont want to put ip details into inventory.
>
> can u help me  here.
>

I am using below playbook with set hostname on xyz server and update host 
file for self. I want to add abc server details into host file of xyz.

vars:

  test_hostname: "xyz"

- name: set up host name
  hostname:
    name: "{{ test_hostname }}"
  register: set_hostname
  tags:
    - set_hostname
  when: test_hostname is defined

- name: Add host entry into host file
  lineinfile:
    dest: /etc/hosts
    regexp: '.*{{ ansible_nodename }}$'
    line: '{{ ansible_default_ipv4.address }} {{ ansible_nodename }} {{ 
ansible_hostname }}'
    state: present


- name: Add other host entry
  lineinfile:
    path: /etc/hosts
    regexp: '.*{{ ansible_nodename }}$'
    #insertafter: '^{{ ansible_nodename }}'
    line: '{{ ansible_default_ipv4.address }} {{ ansible_nodename }}'
    when: inventory_hostname is groups['test1']
  tags:
    - add_host

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/df6be4f7-648b-4b09-b493-135ae64271ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to