Commit 2f7ab90d authored by Alain Takoudjou's avatar Alain Takoudjou

vm-bootstrap: configure hosts file witn hostname of all vm in cluster

parent 8e2f0834
#!/usr/bin/python
import sys
print sys.argv[1:]
host_content = open('/etc/hosts', 'r').read()
hpath = sys.argv[1]
domain = sys.argv[2]
with open('/etc/hosts', 'a') as hosts:
for content in open(hpath, 'r').readlines():
if content:
items = content.strip().split(' ')
entry = "%s %s.%s %s" % (items[1], items[0], domain, items[0])
print entry
if not entry in host_content:
hosts.write(entry)
hosts.write('\n')
......@@ -8,6 +8,10 @@
get_url: url=http://10.0.2.100/ipv4 dest=/etc/opt/ipv4 mode=666
ignore_errors: True
- name: Download cluster.hash
get_url: url=http://10.0.2.100/cluster.hash dest=/tmp/cluster.hash mode=666
ignore_errors: True
- name: stat /etc/opt/hostname
stat: path=/etc/opt/hostname
register: hostname_file
......@@ -16,6 +20,10 @@
stat: path=/etc/opt/ipv4
register: ipv4_file
- name: stat /tmp/cluster.hash
stat: path=/tmp/cluster.hash
register: cluster_hash
- name: replace /etc/hostname
copy: src=/etc/opt/hostname dest=/etc/hostname mode=666
when: hostname_file.stat.exists == True
......@@ -32,6 +40,18 @@
lineinfile: dest=/etc/hosts line="{{ lookup('file', '/etc/opt/ipv4') }} {{ lookup('file', '/etc/opt/hostname') }}.tl.teralab-datascience.fr {{ lookup('file', '/etc/opt/hostname') }}"
when: hostname_file.stat.exists == True
- name: setting cluster
get_url: url="{{ lookup('file', '/tmp/cluster.hash') }}/hosts" dest=/tmp/hosts mode=666 validate_certs=no
when: cluster_hash.stat.exists == True
- name: stat /tmp/hosts
stat: path=/tmp/hosts
register: hostname_file
- name: Format hosts
script: format_hosts /tmp/hosts tl.teralab-datascience.fr
when: cluster_hash.stat.exists == True
- name: managing resolv.conf file
lineinfile: dest=/etc/resolv.conf line="search tl.teralab-datascience.fr"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment