Project setup
Creating the directory structure for a basic Ansible configuration
Executed:
aadmin@uvm0:~$ mkdir -p code/it-wiz/devops/ansible/projects/local/playbooks && cd code/it-wiz/devops/ansible/projects/local
aadmin@uvm0:~/code/it-wiz/devops/ansible/projects/local$ touch ansible.cfg hosts vars.yml
Result
The following directory structure got created:
- ansible.cfg
- hosts
- vars.yml
Populating the configuration files
ansible.cfg
Brought ansible.cfg to the following form:
[defaults]
inventory = hosts
host_key_checking = false
interpreter_python=/home/aadmin/miniconda3/envs/ansible/bin/python
[colors]
error = bright red
hosts
Brought hosts to the following form:
[control]
localhost ansible_connection=local
vars.yml
Brought vars.yml to the following form:
esxi_server: esxihost
esxi_username: esxiadmin
esxi_password: passESXi
Encrypting the vars.yml file
Executed:
aadmin@uvm0:~/code/it-wiz/devops/ansible/projects/local$ ansible-vault encrypt vars.yml --ask-vault-pass
Result
The vars.yml file got encrypted.
Testing the new configuration
Executed:
aadmin@uvm0:~/code/it-wiz/devops/ansible/projects/local$ ansible all --one-line --module-name ping --ask-vault-pass
Vault pasword: <typed my vault password>
localhost | SUCCESS => {"changed": false,"ping": "pong"}
Result
The new configuration worked and Ansible was ready to use it.
Explanations
This was an ad-hoc Ansible command, in which ping was the short name of the ansible.builtin.ping module.