# Forcing a module to run locally?

**URL:** <https://forum.ansible.com/t/forcing-a-module-to-run-locally/13118>\
**Category:** Ansible Project\
**Created:** [July 14, 2013, 6:17pm UTC](https://forum.ansible.com/t/forcing-a-module-to-run-locally/13118 "2013-07-14T18:17:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [July 14, 2013, 6:17pm UTC](https://forum.ansible.com/t/forcing-a-module-to-run-locally/13118/1 "2013-07-14T18:17:18Z")

</div>

How would I optionally force a module to run locally in an action plugin? Can I? If not what is the alternative?

I was almost sure I figured this out but apparently not given Serge bug reports that I reproduced.

[https://github.com/ansible/ansible/pull/3173](https://github.com/ansible/ansible/pull/3173)

I know some modules always run locally – copy etc. I need to do that but “optionally.” I’m trying to support delegate to remote rsyncing were I do want to send the module somewhere rather than run locally.

I’ve been trying all sorts of things to achieve this and have run out of ideas.

Thoughts?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 14, 2013, 10:07pm UTC](https://forum.ansible.com/t/forcing-a-module-to-run-locally/13118/2 "2013-07-14T22:07:13Z")

</div>

The copy action plugin, and others, make use of “\_execute\_module” to get work done.

One of the parameters to \_execute\_module is “inject”, which allows you to add a hash key of “delegate\_to” with a value of localhost.

Hope this helps, if not, let me know!

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [July 18, 2013, 5:02am UTC](https://forum.ansible.com/t/forcing-a-module-to-run-locally/13118/3 "2013-07-18T05:02:31Z")

</div>

Michael: That is what I was doing and after testing some more its not working out. I just setup a test area (not in the office this week) and did some additional investigating. It seems that the connection is established that changing the delegate in the inject data has no effect. See this commit here: [https://github.com/tima/ansible/commit/1bf90df9655fb745dcc687c392d9d0f6b83e7778](https://github.com/tima/ansible/commit/1bf90df9655fb745dcc687c392d9d0f6b83e7778)

Here is the verbose output with some debugging message in my action modules run:

$ ansible -i rsync.ini -m synchronize -a “src=‘./hacking’ dest=‘/tmp/’” --private-key ~/.ssh/gsg-foo.pem -vvv -u ubuntu -c ssh all  
\<[foo.appnel.com](http://foo.appnel.com)\> ESTABLISH CONNECTION FOR USER: ubuntu  
\<[foo.appnel.com](http://foo.appnel.com)\> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/tmp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘IdentityFile=/Users/tima/.ssh/gsg-foo.pem’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=ubuntu’, ‘-o’, ‘ConnectTimeout=10’, ‘[foo.appnel.com](http://foo.appnel.com)’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-1374122730.46-187893212842113 && chmod a+rx $HOME/.ansible/tmp/ansible-1374122730.46-187893212842113 && echo $HOME/.ansible/tmp/ansible-1374122730.46-187893212842113’”]  
DEBUG in synchronize run method now  
DEBUG no delegate defined – setting to 127.0.0.1  
DEBUG remote handling 127.0.0.1 to [foo.appnel.com](http://foo.appnel.com)  
\<[foo.appnel.com](http://foo.appnel.com)\> PUT /var/folders/42/xv4f750d1sb3k8l4vrjn1sz00000gn/T/tmpzzaWBE TO /home/ubuntu/.ansible/tmp/ansible-1374122730.46-187893212842113/synchronize  
\<[foo.appnel.com](http://foo.appnel.com)\> EXEC [‘ssh’, ‘-tt’, ‘-q’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/tmp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘StrictHostKeyChecking=no’, ‘-o’, ‘Port=22’, ‘-o’, ‘IdentityFile=/Users/tima/.ssh/gsg-foo.pem’, ‘-o’, ‘KbdInteractiveAuthentication=no’, ‘-o’, ‘PasswordAuthentication=no’, ‘-o’, ‘User=ubuntu’, ‘-o’, ‘ConnectTimeout=10’, ‘[foo.appnel.com](http://foo.appnel.com)’, “/bin/sh -c ‘/usr/bin/python /home/ubuntu/.ansible/tmp/ansible-1374122730.46-187893212842113/synchronize; rm -rf /home/ubuntu/.ansible/tmp/ansible-1374122730.46-187893212842113/ \>/dev/null 2\>&1’”]

Despite setting inject[‘delete\_to’] to the localhost Ansible does a PUT and EXEC of the module file. Do you or any one recall a change in recent release that moved the connection being established a head of the action module running?

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 18, 2013, 11:40am UTC](https://forum.ansible.com/t/forcing-a-module-to-run-locally/13118/4 "2013-07-18T11:40:31Z")

</div>

Ah yes, that’s done in the task, true.

It’s not a recent change, just something no module has needed to do before.

local\_action is local, that’s for sure. So it’s really a question of just how to force that programatically. I can investigate but it would help if we have a ticket to look into it.

---

<div class="post-metadata">

**Author:** ![Serge\_van\_Ginderacht](https://avatars.discourse-cdn.com/v4/letter/s/b782af/32.png) [@Serge\_van\_Ginderacht](https://forum.ansible.com/u/Serge_van_Ginderacht)\
**Post date:** [July 18, 2013, 12:13pm UTC](https://forum.ansible.com/t/forcing-a-module-to-run-locally/13118/5 "2013-07-18T12:13:19Z")

</div>

FYI, ​I believe this is related to the proposed synchronize (rsync) module:

[https://github.com/ansible/ansible/pull/3173​](https://github.com/ansible/ansible/pull/3173%E2%80%8B)

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [July 18, 2013, 12:17pm UTC](https://forum.ansible.com/t/forcing-a-module-to-run-locally/13118/6 "2013-07-18T12:17:04Z")

</div>

I know that, I’m talking about a new ticket, not the pull request 🙂

---

<div class="post-metadata">

**Author:** ![Timothy\_Appnel](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Timothy\_Appnel](https://forum.ansible.com/u/Timothy_Appnel)\
**Post date:** [July 22, 2013, 2:51am UTC](https://forum.ansible.com/t/forcing-a-module-to-run-locally/13118/7 "2013-07-22T02:51:11Z")

</div>

[https://github.com/ansible/ansible/issues/3612](https://github.com/ansible/ansible/issues/3612)
