-
Notifications
You must be signed in to change notification settings - Fork 2
/
hosts.yml
31 lines (27 loc) · 935 Bytes
/
hosts.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---
- name: Generate hosts file in localhost for all cvm instances
hosts: localhost
tasks:
- name: Copy hosts file
command: cp /etc/hosts hosts
- name: Update ecs IPs in hosts file
lineinfile:
dest: hosts
line: "{{ hostvars[item].qcloud.PublicIpAddresses[0] }} {{ item }}"
with_list: "{{ groups['cvm'] }}"
- name: print some messages
debug:
msg: "Copy hosts to overwrite your /etc/hosts"
- name: Generate hosts file in all cvm instances
hosts: cvm
tasks:
- name: Update ecs IPs in hosts file
lineinfile:
dest: /etc/hosts
line: "{{ hostvars[item].qcloud.PublicIpAddresses[0] }} {{ item }}"
with_list: "{{ groups['cvm'] }}"
- name: Update ecs private IPs in hosts file
lineinfile:
dest: /etc/hosts
line: "{{ hostvars[item].qcloud.PrivateIpAddresses[0] }} {{ item }}"
with_list: "{{ groups['cvm'] }}"