i've found this useful for debugging ansible modules and syntax without having to use VMs or test in dev environments.
pip install ansible
~/.ansible.cfg
:
[defaults]
inventory = ~/.ansible-hosts
Note: used to be hostfile = ~/.ansible-hosts
~/.ansible-hosts
:
localhost ansible_connection=local
helloworld.yml
:
---
- hosts: localhost
connection: local
tasks:
- name: "Print Message"
ansible.builtin.debug:
msg: "Hello World"
Old code:
helloworld.yml
:
---
- hosts: all
tasks:
- shell: echo 'hello world'
run!
$ ansible-playbook helloworld.yml
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [localhost]
TASK [Print Message] **********************************************************************************************
ok: [localhost] => {
"msg": "Hello World"
}
PLAY RECAP ********************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0