
Installation is pretty simple….
1 | $ sudo pacman -Sy ansible sshpass |
Useful dependencies:
Optional dependencies for ansible sshpass: for ssh connections with password python2-passlib: crypt values for vars_prompt python2-netaddr: for the ipaddr filter python2-systemd: log to journal python2-pywinrm: connect to Windows machines python2-dnspython: for dig lookup python2-ovirt-engine-sdk: ovirt support python2-boto: aws_s3 module python2-jmespath: json_query support
We need sshpass for password-based authentication using Ansible.
Run Ansible Locally
Create an inventory hosts file:
1 | $ sudo vim /etc/ansible/hosts |
My one currently has just localhost as the control machine:
[control] 127.0.0.1
You’ll also need to make sure the SSH daemon process is running:
1 2 | $ sudo systemctl start sshd $ sudo systemctl enable sshd |
Also, because by default SSH uses Host key checking which is not supported by sshpass, we first need to SSH locally so we add our fingerprint to our known_hosts file.
1 2 3 4 5 6 7 8 9 10 11 | [andy@home-pc ~]$ ssh andy@127.0.0.1 The authenticity of host '127.0.0.1 (127.0.0.1)' can't be established. ECDSA key fingerprint is SHA256:cynRa21eyQcfrYWjn4ajYiT1E7HBVn7mjfnDDsveiUE. Are you sure you want to continue connecting ( yes /no )? yes Warning: Permanently added '127.0.0.1' (ECDSA) to the list of known hosts. andy@127.0.0.1's password: [andy@home-pc ~]$ exit Connection to 127.0.0.1 closed. [andy@home-pc ~]$ [andy@home-pc ~]$ cat . ssh /known_hosts 127.0.0.1 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBPu9ZWP54Dd5gkCllxGqlYyiwO+ZfHTmCLEJW0K9NR7ThLMxu3yTiQgzjWijN80sEs14U4GHNoc8Qv4DujaVmzU= |
Now we can test it works by using the ansible ping module:
1 2 3 4 5 6 | [andy@home-pc ~]$ ansible control -m ping -u andy --ask-pass SSH password: 127.0.0.1 | SUCCESS => { "changed" : false , "ping" : "pong" } |
Now finally you can run ansible commands locally on your machine.
1 2 3 4 5 6 | [andy@home-pc ~]$ ansible control -u andy --ask-pass -a "free -h" SSH password: 127.0.0.1 | SUCCESS | rc=0 >> total used free shared buff /cache available Mem: 15Gi 732Mi 14Gi 48Mi 638Mi 14Gi Swap: 34Gi 0B 34Gi |
Be the first to comment