Install and configure Ansible on Ubuntu server 20.04
Installing Ansible on Ubuntu Server 20.04 is simple and straight forward.
1. Update Ubuntu repositories and Upgrade.
sudo apt update && sudo apt upgrade
2. Install Ansible
sudo apt install ansible
Output:
winadmin@ansible02:~$ sudo apt install ansible
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
ieee-data python3-argcomplete python3-crypto python3-dnspython python3-jmespath python3-kerberos python3-libcloud
python3-lockfile python3-netaddr python3-ntlm-auth python3-requests-kerberos python3-requests-ntlm python3-selinux
python3-winrm python3-xmltodict
Suggested packages:
cowsay sshpass python-lockfile-doc ipython3 python-netaddr-docs
The following NEW packages will be installed:
ansible ieee-data python3-argcomplete python3-crypto python3-dnspython python3-jmespath python3-kerberos
python3-libcloud python3-lockfile python3-netaddr python3-ntlm-auth python3-requests-kerberos python3-requests-ntlm
python3-selinux python3-winrm python3-xmltodict
0 upgraded, 16 newly installed, 0 to remove and 0 not upgraded.
Need to get 9,643 kB of archives.
After this operation, 90.2 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Press Y
3. Check Ansible version
ansible --version
Output:
ansible 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = ['/home/winadmin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 3.8.10 (default, Jun 2 2021, 10:49:15) [GCC 9.4.0]
4. Check a simple module to check if ansible is working or not. As we have not yet added / updated our inventory file, we can check with localhost.
winadmin@ansible02:~$ ansible localhost -m ping
localhost | SUCCESS => {
"changed": false,
"ping": "pong"
}
Install and configure Ansible on Ubuntu server 18.04
1. Update Ubuntu repositories and Upgrade.
sudo apt update && sudo apt upgrade
2. Check if python is installed. If installed, go to step 3.
python --version
Install Python. If not Python is not installed, ansible will install by default.
sudo apt install python
3. Install Ansible
winadmin@ansible01:~$ sudo apt install ansible
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libdumbnet1
Use 'sudo apt autoremove' to remove it.
The following additional packages will be installed:
ieee-data libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-asn1crypto python-certifi
python-cffi-backend python-chardet python-crypto python-cryptography python-enum34 python-httplib2 python-idna
python-ipaddress python-jinja2 python-jmespath python-kerberos python-libcloud python-lockfile python-markupsafe
python-minimal python-netaddr python-openssl python-paramiko python-pkg-resources python-pyasn1 python-requests
python-selinux python-simplejson python-six python-urllib3 python-xmltodict python-yaml python2.7 python2.7-minimal
Suggested packages:
cowsay sshpass python-doc python-tk python-crypto-doc python-cryptography-doc python-cryptography-vectors
python-enum34-doc python-jinja2-doc python-lockfile-doc ipython python-netaddr-docs python-openssl-doc
python-openssl-dbg python-gssapi python-setuptools python-socks python-ntlm python2.7-doc binutils binfmt-support
Recommended packages:
python-winrm
The following NEW packages will be installed:
ansible ieee-data libpython-stdlib libpython2.7-minimal libpython2.7-stdlib python python-asn1crypto python-certifi
python-cffi-backend python-chardet python-crypto python-cryptography python-enum34 python-httplib2 python-idna
python-ipaddress python-jinja2 python-jmespath python-kerberos python-libcloud python-lockfile python-markupsafe
python-minimal python-netaddr python-openssl python-paramiko python-pkg-resources python-pyasn1 python-requests
python-selinux python-simplejson python-six python-urllib3 python-xmltodict python-yaml python2.7 python2.7-minimal
0 upgraded, 37 newly installed, 0 to remove and 0 not upgraded.
Need to get 12.1 MB of archives.
After this operation, 79.5 MB of additional disk space will be used.
Do you want to continue? [Y/n]Y
4. Once Ansible is installed, check version.
winadmin@ansible01:~$ ansible --version
ansible 2.5.1
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/winadmin/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.17 (default, Nov 7 2019, 10:07:09) [GCC 7.4.0]
5. Check a simple module to check if ansible is working or not. As we have not yet added / updated our inventory file, we can check with localhost.
winadmin@ansible01:~$ ansible localhost -m ping
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match
'all'
localhost | SUCCESS => {
"changed": false,
"ping": "pong"
}