This is the full steps that you can do to implement ansible in debian 9 stretch
Steps:
- Create a Debian stretch VM with the hostname control-server (1st VM)
- Create a Debian stretch VM with the hostname client-server (2nd VM)
- In the 1st VM do: “apt install ansible”
- In 1st VM do : “useradd -d /home/ansadm -m ansadm”
- Then in 1st VM set password of user ansadm by : “passwd ansadm”
- In client-server ( 2nd VM) do step 4-5.
- In control-server (1st vm) do (to login as user ansadm) : “su – ansadm”
- Then in 1st vm itself do : “ssh-keygen -t rsa” press enter till $ sign appear
- Do : “cat /home/ansadm/.ssh/id_rsa.pub” , then copy the key
- Do step 7 in 2nd vm as well
- In 2nd vm create directory .ssh using : “mkdir .ssh”
- In 2nd vm do: “chmod 700 .ssh/” then “chown ansadm:ansadm .ssh/”
- In 2nd vm do: “cd .ssh/” then “nano authorized_keys” and paste the key from step 9 in it and save it.
- Change ownership of authorized_keys by: “chown ansadm:ansadm authorized_keys” and “chmod 600 authorized_keys”
- Test whether keys is working, in 1st vm do : “ssh ip(of 2nd vm)”, it should connect without password, then do “exit”
- in 1st vm, do: “exit” then “chown -R ansadm:ansadm /etc/ansible”
- do step 7 in 1st vm
- do “vim /etc/ansible/hosts” and add this at the bottom :
[webservers]
Ip of 2nd vm
- in 1st vm do “ansible webservers -m ping” to test if 2nd vm connects
- in 2nd vm give ansadm sudo root 20.1. do “apt install sudo” 20.2. “nano /etc/sudoers” 20.3. Add “ansadm ALL=NOPASSWD: ALL” at the bottom
For playbook(all should be done in 1st vm)
-
In 1st vm do step 7 then “cd /etc/ansible”
-
Create file by using : “cat > filename.yml” note: replace filename by any name u want
-
Do “nano filename.yml” note: filename should be the same name which is in step 22
-
paste the content from playbook.yml in the file or simply download the playbook.yml file and place it in a folder. *note: the playbook.yml is only for example purposes, you should create a yml file according to your requirements and it should be well indented and structured.
-
Save file with extension .yml
-
Do “ansible-playbook filename.yml”