Monday, December 7, 2020

Ansible - File copy - update DNS record on client machines

 
Copy name server info to all web servers
1. Disable NetworkManager service
[root@master ~]# systemctl status/stop/disable NetworkManager

2. Update your config file with correct dns entry
[root@master ~]# cat mydns.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 10.0.2.2

3. Write your yaml file
[root@master ~]# cat mydns.yaml
- hosts: myweb
  tasks:
    - copy:
        src: dns.conf
        dest: /etc/resolv.conf

4. Check your ansible config file
[root@master ~]# ansible --version
  config file = /etc/ansible/ansible.cfg

5. Find your inventory file
[root@master ~]# cat /etc/ansible/ansible.cfg | more
[defaults]
inventory      = /root/myhosts
host_key_checking=false

6. Check your inventory record. Set up passwordless authentication (ssh-keygen)
[root@master ~] # cat myhosts
[myweb]
worker1 ansible_user=root ansible_ssh_pass=changeme ansible_connection=ssh
worker2 ansible_user=root ansible_ssh_pass=changeme ansible_connection=ssh

7. Run your playbook
[root@master ~]# ansible-playbook  mydns.yaml

No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...