ansible version available as fact?

309 views
Skip to first unread message

Bryan Larsen

unread,
Apr 11, 2014, 4:33:37 PM4/11/14
to ansible...@googlegroups.com
I have a task that works on devel but not on 1.5.4.   I assume it's because of https://github.com/ansible/ansible/commit/2a976a

- authorized_key: user={{ item|basename }} key="{{ lookup('file', item) }}"
  with_fileglob:
    - "../../../../keys/*"

We have ansible installed on all our production machines so we can do `-c local` deploys.   I don't want to upgrade those machines off of a "stable" version -- if we've gotten far enough to run a `-c local`, at least some of the keys have been installed and we can skip the step.

So I figured I'd just gate the task on ansible_version or some such.   However, there doesn't appear to be such a variable, and I can't find anything like that in -m setup.

Is there some way of figuring out if we're running 1.5 or 1.6 or later and using that in a task?

Alternatively, is there a way of making my task work on 1.5?   It worked on 1.2 and 1.3 (with a different path).

thanks,
Bryan

Matt Martz

unread,
Apr 11, 2014, 9:15:50 PM4/11/14
to ansible...@googlegroups.com
Not quite yet. Have a look at https://github.com/ansible/ansible/pull/6619
--
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.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0c4b39f5-6f54-44c7-8d5b-aecbb822f669%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
ma...@sivel.net
http://sivel.net/

Serge van Ginderachter

unread,
Apr 12, 2014, 4:36:42 AM4/12/14
to ansible...@googlegroups.com
On 12 April 2014 03:15, Matt Martz <ma...@sivel.net> wrote:
Not quite yet. Have a look at https://github.com/ansible/ansible/pull/6619

​For now I guess you could work around with a pipe lookup running ansible --version​

​In the mean time also https://github.com/ansible/ansible/pull/6835 was merged, ​which gives you a version_compare  filter.


   Serge 


Bryan Larsen

unread,
Apr 21, 2014, 4:32:05 PM4/21/14
to ansible...@googlegroups.com
I've got a role that works in 1.6 but crashes in 1.5.   (My guess is that this fixes it:  https://github.com/ansible/ansible/commit/2a976a)

The crashing task is this:

- authorized_key: user={{ item|basename }} key="{{ lookup('file', item) }}"
  with_fileglob:
    - "../../../../keys/*"

The role is one that I'm happy running manually for now, so I thought I'd gate it with something like:

  roles:
   - { role: 'users', when: 'ansible_version is defined' } 

(this assumes https://github.com/ansible/ansible/pull/6619 will land soon.   For now, I'm just using -e)

This skips the role, but it's still being parsed and crashing ansible.

Suggestions?

Michael DeHaan

unread,
Apr 21, 2014, 7:23:48 PM4/21/14
to ansible...@googlegroups.com
If you would ever like to report a crash, including the "result" of the crash is needed to understand the context.

Can you please paste the result you are receiving?


--
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.
To post to this group, send email to ansible...@googlegroups.com.

Bryan Larsen

unread,
Apr 22, 2014, 11:23:38 AM4/22/14
to ansible...@googlegroups.com
On Mon, Apr 21, 2014 at 7:23 PM, Michael DeHaan <mic...@ansible.com> wrote:
If you would ever like to report a crash, including the "result" of the crash is 
needed to understand the context.
Can you please paste the result you are receiving?
 
I'm not sure why you want the backtrace; it's already fixed in 1.6 by https://github.com/ansible/ansible/commit/2a976a.   I've attached the backtrace at the end of this email.

The actual crash is not my concern.   There are several different ways that you can crash ansible on skipped roles.   Another way to do it is via

    with_sequence: start=1 end={{ numFoo }}

where numFoo is 0.   That obviously should be an error when the task is run.   What is surprising that ansible still crashes with "can't count backwards" even if you tell it to skip the role containing the task:

   - { role: 'foo', when: 'numFoo > 0' }

This can be worked around through judicious use of the default filter.   It's just annoying.   My original email in this thread outlined a situation where I couldn't find a workaround, and asks for one.   I can run ansible 1.6 locally, but I need my playbook to be compatible with 1.5.   It's OK if it skips problematic plays.

thanks,
Bryan



Traceback (most recent call last):
  File "/exo/ansible/bin/ansible-playbook", line 307, in <module>
    sys.exit(main(sys.argv[1:]))
  File "/exo/ansible/bin/ansible-playbook", line 247, in main
    pb.run()
  File "/exo/ansible/lib/ansible/playbook/__init__.py", line 286, in run
    if not self._run_play(play):
  File "/exo/ansible/lib/ansible/playbook/__init__.py", line 659, in _run_play
    if not self._run_task(play, task, False):
  File "/exo/ansible/lib/ansible/playbook/__init__.py", line 405, in _run_task
    self.callbacks.on_task_start(template(play.basedir, name, task.module_vars, lookup_fatal=False, filter_fatal=False), is_handler)
  File "/exo/ansible/lib/ansible/utils/template.py", line 321, in template
    varname = template_from_string(basedir, varname, vars, fail_on_undefined)
  File "/exo/ansible/lib/ansible/utils/template.py", line 562, in template_from_string
    res = jinja2.utils.concat(rf)
  File "<template>", line 12, in root
  File "/usr/lib/python2.7/dist-packages/jinja2/runtime.py", line 193, in call
    return __obj(*args, **kwargs)
  File "/exo/ansible/lib/ansible/utils/template.py", line 554, in my_lookup
    return lookup(*args, basedir=basedir, **kwargs)
  File "/exo/ansible/lib/ansible/utils/template.py", line 91, in lookup
    ran = instance.run(*args, inject=vars, **kwargs)
  File "/exo/ansible/lib/ansible/runner/lookup_plugins/file.py", line 42, in run
    ret.append(codecs.open(path, encoding="utf8").read().rstrip())
  File "/usr/lib/python2.7/codecs.py", line 881, in open
    file = __builtin__.open(filename, mode, buffering)
IOError: [Errno 21] Is a directory: '/exo/ExocortexStudioServices/deploy/ansible/roles/users/files'

Michael DeHaan

unread,
Apr 23, 2014, 9:08:24 AM4/23/14
to ansible...@googlegroups.com
On Tue, Apr 22, 2014 at 11:23 AM, Bryan Larsen <br...@larsen.st> wrote:
On Mon, Apr 21, 2014 at 7:23 PM, Michael DeHaan <mic...@ansible.com> wrote:

If you would ever like to report a crash, including the "result" of the crash is 
needed to understand the context.
Can you please paste the result you are receiving?
 
I'm not sure why you want the backtrace; it's already fixed in 1.6 by https://github.com/ansible/ansible/commit/2a976a.   I've attached the backtrace at the end of this email.


It's entirely because you send an email reporting a crash :)
 

The actual crash is not my concern.  


Should have probably indicated that in the first email :)


 
There are several different ways that you can crash ansible on skipped roles.   Another way to do it is via

    with_sequence: start=1 end={{ numFoo }}

where numFoo is 0.   That obviously should be an error when the task is run.   What is surprising that ansible still crashes with "can't count backwards" even if you tell it to skip the role containing the task:

Conditionals are applied per loop step, not before the loop is evaluated.
 
Reply all
Reply to author
Forward
0 new messages