Monday, July 11, 2022

My first steps in Ansible

Today I decided to learn Ansible

These are just my study notes and not a technical advices at all.


I setup 3 ubuntu 20 servers and and 1 of them will act as a ansible master node and the 2 other servers will act as clients.


first step is to install ansible on the master server with the below command:

apt-get install ansible

then I created a hosts file with the ini format not YAML one because it is more complicated 

cat ansible/hosts/hosts.ini

[client01]

10.x.y.z ansible_user=root ansible_password=ABC123


[client02]

10.a.b.c ansible_user=root ansible_password=XYZ123


ansible client01 -i ansible/hosts/hosts.ini -m ping

ansible_host=10.11.25.67 | FAILED! => {

    "msg": "to use the 'ssh' connection type with passwords, you must install the sshpass program"

}


now we will have to setup this package

apt-get install sshpass


ansible client01 -i ansible/hosts/hosts.ini -m ping
10.11.25.67 | FAILED! => {
    "msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."
}

and now I have to add the host's finger print 

ssh root@10..X.Y.Z
The authenticity of host '10..X.Y.Z (10..X.Y.Z)' can't be established.
ECDSA key fingerprint is SHA256:d/12345UOor12345/viwg16/oHAec5sa/12345.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10..X.Y.Z' (ECDSA) to the list of known hosts.


ansible client01 -i ansible/hosts/hosts.ini -m ping
10..X.Y.Z | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}

No comments:

Post a Comment

Install Vault on ubuntu 20

 Today I will install vault on ubuntu 20 to use it as a part of my Ansible learning journey  Add GPG key curl -fsSL https://apt.releases.has...