-
Notifications
You must be signed in to change notification settings - Fork 3
/
playbook-hosts.yml
42 lines (35 loc) · 1.44 KB
/
playbook-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
32
33
34
35
36
37
38
39
40
41
---
- hosts: all
become: true
become_user: root
become_method: sudo
gather_facts: yes
vars:
internal_domain: example.org
tasks:
- name: setting hostname from inventory
hostname: name="{{ inventory_hostname }}.{{ internal_domain }}"
when: internal_domain is defined
- name: setting hostname from inventory
hostname: name="{{ inventory_hostname }}"
when: internal_domain is not defined
- name: generate static hosts as defined
blockinfile:
dest: /etc/hosts
block: |
10.64.32.1 database-master database-master.{{ internal_domain }}
10.64.64.1 database-backup database-backup.{{ internal_domain }}
10.64.128.10 monitor-server-1 monitor-server-1.{{ internal_domain }}
10.64.228.10 monitor-server-2 monitor-server-2.{{ internal_domain }}
10.64.128.20 rsyslog-server-1 rsyslog-server-1.{{ internal_domain }}
10.64.228.20 rsyslog-server-2 rsyslog-server-2.{{ internal_domain }}
10.64.128.20 ssh-proxy-host-1 ssh-proxy-host-1.{{ internal_domain }}
10.64.228.20 ssh-proxy-host-2 ssh-proxy-host-2.{{ internal_domain }}
- name: generate dynamic hosts from inventory
lineinfile:
state: present
dest: /etc/hosts
regexp: '.*{{ item }}$'
line: "{{ hostvars[item].ansible_host }} {{item}}"
when: hostvars[item].ansible_host is defined
with_items: "{{ groups['all'] }}"