local_action and register

1,426 views
Skip to first unread message

Edgars

unread,
May 14, 2013, 6:16:01 AM5/14/13
to ansible...@googlegroups.com
Hi there

I have some troubles to get register variable from local_action. Here is what I have:

---
  - name: deploy something
    hosts: all
    sudo: True

   vars:
     hostname: ${ansible_hostname}

    tasks:
    - name: Checking
      local_action: command /bin/something ${hostname}
      register: status

    - name: doing something
      local_action: command /bin/something_else ${hostname}
      only_if: "$status.rc != 0"

    - name: deploying to remote nodes
      action: template src=/var/repository/config.j2 dest=/etc/config owner=root group=root mode=0644

And here is what I get:

(...)

TASK: [Checking] *********************
skipping: [Host_A]

TASK: [doing something] *********************
fatal: [Host_A] => Could not evaluate the expression: $git_exists.rc != 0

FATAL: all hosts have already failed -- aborting


(...)

Why is task "Checking" skipped and why that expression cannot be evaluated?


Thanks
Edgars

Serge van Ginderachter

unread,
May 14, 2013, 6:27:18 AM5/14/13
to ansible...@googlegroups.com

On 14 May 2013 12:16, Edgars <edgars...@gmail.com> wrote:
TASK: [Checking] *********************
skipping: [Host_A]

TASK: [doing something] *********************
fatal: [Host_A] => Could not evaluate the expression: $git_exists.rc != 0


​Where you running that playbook in check mode?


Edgars

unread,
May 14, 2013, 6:54:43 AM5/14/13
to ansible...@googlegroups.com
Yes, I were running it in check mode.

Serge van Ginderachter

unread,
May 14, 2013, 7:44:39 AM5/14/13
to ansible...@googlegroups.com

On 14 May 2013 12:54, Edgars <edgars...@gmail.com> wrote:
Yes, I were running it in check mode.

​That's why the command tasks are skipped (they don't support check mode).
And then the variable doesn't get registered, which is why it fails in the next step.

Serge​

Michael DeHaan

unread,
May 14, 2013, 8:20:31 AM5/14/13
to ansible...@googlegroups.com
"      only_if: "$status.rc != 0""

BTW, only _if is extremely dated syntax.   In 1.1 this was improved with when_integer, and in 1.2 (current development release but many many people run from source and it's quite stable now) both only_if and when_* are deprecated.

when:  status:rc != 0

What you want in this case is actually:

when:  status is defined and status.rc != 0



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Michael DeHaan <mic...@ansibleworks.com>
CTO, AnsibleWorks, Inc.
http://www.ansibleworks.com/

Edgars

unread,
May 14, 2013, 8:40:03 AM5/14/13
to ansible...@googlegroups.com
Ok, thanks everyone. I am very suspicious and always run check mode :)

I am aware of only_if and when, but since both of them did not work, I left only_if.

Regarding outdated syntax - perhaps --syntax-check should warn about deprecated syntax? It's not always possible to track all changes, but --syntax-check seems to be a godd way how to warn about them!?

Edgars

zperry

unread,
Jul 9, 2013, 4:24:57 PM7/9/13
to ansible...@googlegroups.com
But as of today, July 9, 2013, the examples for the debug module are still using the only_if expression?

-- Zack


BTW, only _if is extremely dated syntax.   In 1.1 this was improved with when_integer, and in 1.2 (current development release but many many people run from source and it's quite stable now) both only_if and when_* are deprecated.

[...]

Jesse Keating

unread,
Jul 9, 2013, 5:28:15 PM7/9/13
to ansible...@googlegroups.com
On Jul 9, 2013, at 1:24 PM, zperry <zack....@sbcglobal.net> wrote:
>
> But as of today, July 9, 2013, the examples for the debug module are still using the only_if expression?

Easily fixed with a pull request. I've been doing that for the docs I come across that are dated.

-jlk

Michael DeHaan

unread,
Jul 9, 2013, 9:04:49 PM7/9/13
to ansible...@googlegroups.com
I have a ticket on this already.   Will get to it if there is not a pull request.




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply all
Reply to author
Forward
0 new messages