It may be useful to run an Ansible playbook on a local system.
For example for putting a playbook in a
crontab or for a new host provisioning.
In this note i am showing the several ways to run Ansible playbook locally.
Cool Tip: Enable DEBUG mode and increase VERBOSITY in Ansible! Read more →
Run Ansible Playbook Locally
Run an Ansible playbook on the
# playbook.yml: --- - name: "Ansible playbook example" hosts: 127.0.0.1 connection: local tasks: - name: "Check out a Git repository on the Ansible host" git: repo: git://github.com/path/to/repo.git dest: /local/path
Run only a single task locally:
# playbook.yml: --- - name: "Ansible playbook example" hosts: webservers tasks: - ... - name: "Check out a Git repository on the Ansible host" local_action: module: git repo: git://github.com/path/to/repo.git dest: /local/path
Run an Ansible playbook locally from the command line:
$ ansible-playbook --connection=local 127.0.0.1, playbook.yml
Note, that the comma after
127.0.0.1, is mandatory, otherwise
127.0.0.1 is treated like a file name, that will cause the following errors:
[WARNING]: Unable to parse …/127.0.0.1 as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’