Skip to content

Instantly share code, notes, and snippets.

@IssacTran
Forked from rothgar/main.yml
Created June 21, 2016 07:44
Show Gist options
  • Save IssacTran/a99b94674430dad14a6b91570ac701a9 to your computer and use it in GitHub Desktop.
Save IssacTran/a99b94674430dad14a6b91570ac701a9 to your computer and use it in GitHub Desktop.

Revisions

  1. @rothgar rothgar revised this gist Feb 3, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion main.yml
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    # Idempotent way to build a /etc/hosts file with Ansible using your Ansible hosts inventory for a source. Will include all hosts the playbook is run on. Inspired from http://xmeblog.blogspot.com/2013/06/ansible-dynamicaly-update-etchosts.html
    # Idempotent way to build a /etc/hosts file with Ansible using your Ansible hosts inventory for a source.
    # Will include all hosts the playbook is run on.
    # Inspired from http://xmeblog.blogspot.com/2013/06/ansible-dynamicaly-update-etchosts.html

    - name: "Build hosts file"
    lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" state=present
  2. @rothgar rothgar revised this gist Feb 3, 2014. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions main.yml
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Idempotent way to build a /etc/hosts file with Ansible using your Ansible hosts inventory for a source. Will include all hosts the playbook is run on. Inspired from http://xmeblog.blogspot.com/2013/06/ansible-dynamicaly-update-etchosts.html

    - name: "Build hosts file"
    lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" state=present
    when: hostvars[item].ansible_default_ipv4.address is defined
  3. @rothgar rothgar revised this gist Feb 3, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions main.yml
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    - name: "Build hosts file"
    lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item]['ansible_default_ipv4']['address'] }} {{item}}" state=present
    when: hostvars[item]['ansible_default_ipv4']['address'] is defined
    lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" state=present
    when: hostvars[item].ansible_default_ipv4.address is defined
    with_items: groups['all']
  4. @rothgar rothgar created this gist Feb 3, 2014.
    4 changes: 4 additions & 0 deletions main.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    - name: "Build hosts file"
    lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item]['ansible_default_ipv4']['address'] }} {{item}}" state=present
    when: hostvars[item]['ansible_default_ipv4']['address'] is defined
    with_items: groups['all']