Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@alces
Last active April 5, 2024 18:28
Show Gist options
  • Save alces/caa3e7e5f46f9595f715f0f55eef65c1 to your computer and use it in GitHub Desktop.
Save alces/caa3e7e5f46f9595f715f0f55eef65c1 to your computer and use it in GitHub Desktop.
How to run an Ansible playbook locally
  • using Ansible command line:
ansible-playbook --connection=local 127.0.0.1 playbook.yml
  • using inventory:
127.0.0.1 ansible_connection=local
  • using Ansible configuration file:
[defaults]
transport = local
  • using playbook header:
- hosts: 127.0.0.1
  connection: local
@wazcov
Copy link

wazcov commented Nov 28, 2019

which is recommended or best practice?

@alces
Copy link
Author

alces commented Nov 29, 2019

I don't know anything about official best practices, but by myself most often use the last variant (i.e., playbook header).

@q2dg
Copy link

q2dg commented Jan 12, 2020

But if I have'nt understood this badly (https://docs.ansible.com/ansible/latest/inventory/implicit_localhost.html), it isn't necessary to indicate explicitely the connection type: just writing "localhost" as target will make Ansible to infer it has to make a "local" connection, isn't?

@alces
Copy link
Author

alces commented Jan 13, 2020

I'm not sure it worked this way in all versions of Ansible I'd previously coded for, so I used to always add connection: local just to make sure that the connection will not go through SSL.

@lihongjie0209
Copy link

ansible-playbook -c local -i localhost, ini.yaml

@Subbaraman-Sowmya
Copy link

ubuntu@ip-172-31-28-5:$ ansible-playbook -c local -i localhost, sample-play.yaml
ERROR! the playbook: sample-play.yaml could not be found
ubuntu@ip-172-31-28-5:
$ ansible-playbook -c local -i localhost, sample-play.yml
ERROR! the playbook: sample-play.yml could not be found
ubuntu@ip-172-31-28-5:$ vi sample-play.yml
ubuntu@ip-172-31-28-5:
$ ansible-playbook -c local -i localhost, sample-play.yml
[WARNING]: Could not match supplied host pattern, ignoring: host1

PLAY [Installing apache2 on host1] *********************************************************************************************************************************************
skipping: no hosts matched
[WARNING]: Could not match supplied host pattern, ignoring: host2

PLAY [Installing nginx on host2] ***********************************************************************************************************************************************
skipping: no hosts matched

PLAY RECAP *********************************************************************************************************************************************************************

@GregOriol
Copy link

Thanks a lot, this is so annoying to figure out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment