- Here is a video tutorial
Scripts and configuration files are available
here:
- Install ansible
SLES | openSUSE Leap 15.4
1
|
sudo zypper install ansible
|
Debian
1
|
sudo apt install ansible
|
Red Hat
1
|
sudo dnf install ansible
|
- Create ansible directory on /etc
1
|
sudo mkdir /etc/ansible
|
- Create hosts file inside the /etc/ansible directory
1
|
sudo vim /etc/ansible/hosts
|
and put the below content into the file
1
2
3
4
5
6
7
8
9
10
11
|
servers:
hosts:
worker1:
ansible_host: 10.10.0.3
ansible_user: ansible
worker2:
ansible_host: 10.10.0.4
ansible_user: ansible
master:
ansible_host: 10.10.0.2
ansible_user: ansible
|
- Check ansible version
-
Make sure that PasswordAuthentication has set boolean value to yes in /etc/ssh/sshd_config file on remote servers.
-
Create two playbooks. See examples below:
1
2
3
4
|
- hosts: servers
tasks:
- name: "connect via ssh"
shell: for i in $(cat servers); do ssh ansible@$i; done
|
1
2
3
4
5
6
7
|
- hosts: servers
become: true
tasks:
- name: "replace on sshd_config"
shell: sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
- name: "Restart ssh"
shell: systemctl restart sshd
|
- Run these playbooks like below:
1
2
3
|
ansible-playbook ssh-session.yaml
ansible-playbook passwd-auth.yaml
ansible-playbook ssh-session.yaml
|