-
Notifications
You must be signed in to change notification settings - Fork 15
/
hosts.yml
29 lines (29 loc) · 1.06 KB
/
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
---
- name: Generate hosts file in localhost for all ecs instances
hosts: localhost
tasks:
- name: Copy hosts file
command: cp /etc/hosts hosts
- name: Update ecs IPs in hosts file
lineinfile:
dest: hosts
regexp: "^{{ hostvars[item].aliyun.PublicIp | replace('.', '\\.') }}"
line: "{{ hostvars[item].aliyun.PublicIp }} {{ item }}.aliyun"
with_items: groups.ecs
- debug: msg="Copy hosts to overwrite your /etc/hosts"
- name: Generate hosts file in all ecs instances
hosts: ecs
sudo: true
tasks:
- name: Update ecs IPs in hosts file
lineinfile:
dest: /etc/hosts
regexp: "^{{ hostvars[item].aliyun.PublicIp | replace('.', '\\.') }}"
line: "{{ hostvars[item].aliyun.PublicIp }} {{ item }}.aliyun"
with_items: groups.ecs
- name: Update ecs private IPs in hosts file
lineinfile:
dest: /etc/hosts
regexp: "^{{ hostvars[item].aliyun.InnerIp | replace('.', '\\.') }}"
line: "{{ hostvars[item].aliyun.InnerIp }} {{ item }}.private"
with_items: groups.ecs