nedeľa 13. februára 2022

ansible playbook for migrating /etc/hosts

ansible is awesome and ssh is the best. Nothing more.  (Of course, your brain) 







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: 


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 




Žiadne komentáre:

Zverejnenie komentára