Merge "Generate full /etc/hosts on every node"

This commit is contained in:
Jenkins 2016-09-15 14:40:52 +00:00 committed by Gerrit Code Review
commit bac19675ed
2 changed files with 9 additions and 41 deletions

View File

@ -1,17 +0,0 @@
---
- name: get real node hostname
shell: echo $(hostname)
register: real_node_hostname
delegate_to: "{{ control_node }}"
- name: get real node ip
shell: ip -4 addr show "{{ hostvars[control_node]['api_interface'] }}" | grep -oP "(?<=inet )[\d\.]+(?=/)"
register: real_node_ip
delegate_to: "{{ control_node }}"
- name: Insert hosts entries for all kolla-ansible hosts
lineinfile:
dest=/etc/hosts
line="{{ real_node_ip.stdout }} {{ real_node_hostname.stdout.split('.')[0] }} {{ real_node_hostname.stdout }} {{ '#' }}a_kolla_ansible_host"
insertafter=".*kolla-ansible\ hosts"
state=present

View File

@ -20,30 +20,15 @@
become: True become: True
when: customize_etc_hosts | bool == True when: customize_etc_hosts | bool == True
- name: Remove all previous kolla-ansible hosts entries to prevent cruft - name: Generate etc/hosts
lineinfile: blockinfile:
dest=/etc/hosts dest: /etc/hosts
regexp="{{ '#' }}a_kolla-ansible_host" marker: "# {mark} ANSIBLE GENERATED HOSTS"
state=absent block: |
become: True {% for host in groups['all'] %}
when: customize_etc_hosts | bool == True {{ hostvars[host]['ansible_' + hostvars[host]['api_interface']]['ipv4']['address'] }} {{ hostvars[host]['ansible_hostname'] }}
{% endfor %}
- name: Insert a comment after EOF to put our entries under, IF it is not already present when: customize_etc_hosts | bool
lineinfile:
dest=/etc/hosts
regexp="{{ '#' }}kolla-ansible hosts"
line="{{ '#' }}kolla-ansible hosts"
insertafter=EOF
state=present
become: True
when: customize_etc_hosts | bool == True
- include: append_to_etc_hosts.yml
with_inventory_hostnames: control
loop_control:
loop_var: control_node
become: True
when: customize_etc_hosts | bool == True
- name: ensure sudo group is present - name: ensure sudo group is present
group: name=sudo state=present group: name=sudo state=present