Is it possible to run commands on the Ansible host?
My scenario is that I want to take a checkout from a git server that is hosted internally (and isn\'t accessible
I'd like to share that Ansible can be run on localhost via shell:
ansible all -i "localhost," -c local -m shell -a 'echo hello world'
This could be helpful for simple tasks or for some hands-on learning of Ansible.
The example of code is taken from this good article:
Running ansible playbook in localhost
You can use delegate_to
to run commands on your Ansible host (admin host), from where you are running your Ansible play. For example:
Delete a file if it already exists on Ansible host:
- name: Remove file if already exists
file:
path: /tmp/logfile.log
state: absent
mode: "u+rw,g-wx,o-rwx"
delegate_to: 127.0.0.1
Create a new file on Ansible host :
- name: Create log file
file:
path: /tmp/logfile.log
state: touch
mode: "u+rw,g-wx,o-rwx"
delegate_to: 127.0.0.1