I'm trying to use a task where the filenames are determined by variables,
running into what looks like the same issue, and wondering how best to
accomplish what I want to do. I'm using Ansible 1.9.1.
Within a role, I have two task files for installing two versions of the
same component that install in different ways.
In the role's defaults, I have two variables: component_version and
component_main_version.
The component_main_version variable is defined in the defaults/main.yml
this way:
component_main_version: "{{ component_version[0:1] }}"
My intention is to pull the main version number (e.g. 4) from the full
version number (e.g. 4.8.1).
In tasks/main.yml, I have - include: component_{{ component_main_version
}}.yml.
When I run my playbook I get
ERROR: file could not read: /path/to/role/tasks/component_{{
component_main_version }}.yml
If I pass the variable at the command line:
-e component_main_version=4
I get the desired behavior.
Am I defining the derived variable incorrectly? Am I running up against the
bug described here? Is there a better way to accomplish what I'm trying to
do?
Any insight/help greatly appreciated.
Thanks,
Alicia
On Wednesday, December 3, 2014 at 4:43:35 PM UTC-6, Ross Becker wrote:
>
> Funny enough, in prior versions and in dev branch, having those facts come
> in via a "vars:" statement in the playbook works. Most places they're
> being used, they come in via extra-vars, and it wouldn't have been a big
> deal to change this instance to match that, but not working at all would've
> been a big deal.
>
> On Wednesday, December 3, 2014 1:49:49 PM UTC-8, Michael DeHaan wrote:
>>
>> Also I'd double check that those two vars in the include do not come from
>> facts or inventory.
>>
>> (That would have been any any-version thing)
>>
>>
>> On Wed, Dec 3, 2014 at 4:38 PM, Brian Coca <[email protected]> wrote:
>>
>>> a few bugs with variables were present in 1.8.x, could you test with
>>> current devel as there are fixes there (soon to be released) that
>>> might solve your issue.
>>>
>>> On Wed, Dec 3, 2014 at 4:31 PM, Ross Becker <[email protected]> wrote:
>>> > So, I have a batch of playbooks that include tasks where the filenames
>>> are
>>> > determined by variables;
>>> >
>>> > - include: tasks/mytask-{{onevar}}-{{anothervar}}.yml
>>> >
>>> > This was working up through ansible 1.7.2. As of ansible 1.8.0 (and
>>> also
>>> > tested on ansible 1.8.1) this stopped working; the variables are no
>>> longer
>>> > interpreted, and ansible exits complaining with a message:
>>> >
>>> > ERROR: file could not read:
>>> /root/work/playbooks/tasks/bar-{{platform}}.yml
>>> >
>>> >
>>> > Below are the bits to reproduce:
>>> >
>>> > foo.yml:
>>> > - hosts: slave
>>> > user: root
>>> >
>>> > vars:
>>> > platform: rpm
>>> >
>>> > tasks:
>>> > - include: "tasks/bar-{{platform}}.yml"
>>> >
>>> > tasks/bar-rpm.yml:
>>> > - name: install OS package dependencies
>>> > action: yum pkg={{item}} state=installed
>>> > with_items:
>>> > - wget
>>> > - ntpdate
>>> >
>>> >
>>> > hosts.inv:
>>> > [slave]
>>> > sc-cluster-20-04
>>> > sc-cluster-20-05
>>> > sc-cluster-20-06
>>> >
>>> >
>>> >
>>> > The above case works on all ansible versions up through 1.7.2, and
>>> breaks on
>>> > 1.8.0+. I searched on here a bit regarding this, and found the
>>> suggestion
>>> > that variables as part of include filenames would only work if passed
>>> in as
>>> > extra vars, as only those would be resolvable early enough. I tested
>>> that
>>> > on 1.7.2 by taking out the "vars:" section and passing the value in as
>>> an
>>> > extra var on the command-line. That test worked on 1.7.2 and earlier,
>>> but
>>> > does not work in 1.8.0+.
>>> >
>>> > Is there any means where this functionality should actually work in
>>> 1.8.x?
>>> >
>>> > --
>>> > 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 [email protected].
>>> > To post to this group, send email to [email protected].
>>> > To view this discussion on the web visit
>>> >
>>> https://groups.google.com/d/msgid/ansible-project/c2604edb-dc50-4770-82e1-d638e099b766%40googlegroups.com
>>> .
>>> > For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>>>
>>> --
>>> Brian Coca
>>>
>>> --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/CAJ5XC8kLBbfRctHR2nKSjPu4P_p3d3OGnZxpydRc7qgQEwxwDw%40mail.gmail.com
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/22a7d804-c79e-4fc8-a48b-154d80be2134%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.