Forcing a module to run locally?

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

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?

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!

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

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> ESTABLISH CONNECTION FOR USER: ubuntu
<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’, “/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
<foo.appnel.com> PUT /var/folders/42/xv4f750d1sb3k8l4vrjn1sz00000gn/T/tmpzzaWBE TO /home/ubuntu/.ansible/tmp/ansible-1374122730.46-187893212842113/synchronize
<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’, “/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?

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.

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

https://github.com/ansible/ansible/pull/3173​

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

https://github.com/ansible/ansible/issues/3612