Ansible will be used all across to automate installing things onto our VM. This guide covers the basic for installation and to verify that Ansible is working for local. Ansible install will work as well for any other command Ansible workflow.
Refresh the system's package index:
sudo apt update
Install Ansible:
sudo apt install ansible
Check installed version:
$ ansible --version
ansible 2.10.8
config file = None
configured module search path = ['/home/rui/.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.10.4 (main, Apr 2 2022, 09:04:19) [GCC 11.2.0]
Note Your
$HOME
should have your user. Thisrui
is my case.
Note I know very little about Ansible so make no assumptions about this process being the most correct. Certainly I'll come back to this and redo this guide/steps.
I've took inspiration from Adam Monsen Ansible Hello World and Alexey Zalesny How to run an Ansible playbook locally gist.
-
Create a playbooks folder:
mkdir playbooks
-
Move to the new folder and create hosts file with the following content:
[test] rui-virtual-machine ansible_connection=local
Note This is my example hostname
rui-virtual-machine
change it accordingly to match your VM hostname. -
Now create a file named hello.yml with the following content:
- hosts: rui-virtual-machine tasks: # see https://docs.ansible.com/ansible/ping_module.html - name: test connection ping:
-
Let's run the playbook:
$ ansible-playbook -i hosts hello.yml PLAY [rui-virtual-machine] ************************************************************************** TASK [Gathering Facts] ****************************************************************************** ok: [rui-virtual-machine] TASK [test connection] ****************************************************************************** ok: [rui-virtual-machine] PLAY RECAP ****************************************************************************************** rui-virtual-machine : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Nice, we can run Ansible playbooks. We could also run the
ping
module directly and see more details about the hosts, in this case our guest VM:$ ansible all -i hosts -m ping rui-virtual-machine | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3" }, "changed": false, "ping": "pong" }