# Same playbook executed locally and remotely

**URL:** <https://forum.ansible.com/t/same-playbook-executed-locally-and-remotely/33658>\
**Category:** Ansible Project\
**Created:** [August 22, 2020, 5:44pm UTC](https://forum.ansible.com/t/same-playbook-executed-locally-and-remotely/33658 "2020-08-22T17:44:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhalano](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mhalano/32/1815_2.png) [@mhalano](https://forum.ansible.com/u/mhalano)\
**Post date:** [August 22, 2020, 5:44pm UTC](https://forum.ansible.com/t/same-playbook-executed-locally-and-remotely/33658/1 "2020-08-22T17:44:27Z")

</div>

Hi fellows!

I’m trying to build a playbook for my infrastructure but I would like to be able to do something like this:  
ansible-playbook -i hosts site.yml  
This playbook is quite simple, just some lines like this:

- import\_playbook: glados.yml
- import\_playbook: skynet.yml
- import\_playbook: brainiac.yml  
No big deal until now. The problem is: I also want to use ansible-pull so the machines (glados, skynet, brainiac, and so on) also be able to git clone and execute their respective playbook by themselves.

The problem is all around what I should put on “hosts:” line. If I just put “localhost” or “127.0.0.1” just the ansible-pull will work. and if put the hostname just the ansible-playbook with the site.yml will work (because I have entries on the inventory file).

I quite resolved that creating a script to automate the installation (just execute the script into the machine and the magic happens) which generates a for-locally-use-only inventory:  
echo “glados ansible\_host=127.0.0.1 ansible\_connection=local ansible\_python\_interpreter=/usr/bin/python3” | sudo tee /etc/ansible/hosts

This allows me to use this host-only inventory to execute the ansible-pull and a broder inventory with the correct IPs to execute site.yml.

THere is a better, more elegant solution available?
