We need /etc/hosts the same on 200 servers. How to do it?
1) create on "ansible server" template (or templates)
- you know:
- /etc/hosts for db servers
- /etc/hosts for application servers
- /etc/hosts for redis servers
- /etc/hosts for backup servers
- /etc/hosts for monitoring servers
2) ssh connection from "ansible servers" to other servers
3) creating playbook etc_hosts.yaml
4) check yaml validator
5) take a beer
point 1:
--> template is "local repository"
mkdir -p /etc/ansible/templates
vi /etc/ansible/templates/db_server_etc_hosts
vi /etc/ansible/templates/app_server_etc_hosts
vi /etc/ansible/templates/redis_server_etc_hosts
This is my "local ansible repository" - it is very easy only 1 file:
[root@localhost playbooks]# ls -l /etc/ansible/templates/
total 4
-rw-r--r--. 1 root root 811 Feb 13 07:37 db_servers_hosts
point 2: ssh connection:
in ansible we can use this: https://zapiskylinuxadmina.blogspot.com/2022/01/ansible-ping.html
point 3: creating playbook. yaml file:
I have playbooks in /etc/ansible/playbooks
[root@localhost playbooks]# cat /etc/ansible/playbooks/hosts.yaml
The playbook:
---
- hosts: all
tasks:
- name : migrating /etc/hosts from template
copy: src=/etc/ansible/templates/db_servers_hosts dest=/etc/hosts mode=644 owner=root group=root
point 4: use yaml validator
point 5:
This playbook is similar as playbook for migration cron https://zapiskylinuxadmina.blogspot.com/2022/02/ansible-migrating-crontab.html
I have github with my ansible playbooks: https://github.com/marsur/ansible_study
migration /etc/hosts playbook on github: https://github.com/marsur/ansible_study/blob/main/etc_hosts.yaml
picuter with beer: https://docs.brew.sh/Homebrew-on-Linux
Žiadne komentáre:
Zverejnenie komentára