Have you considered conditional includes 
<http://docs.ansible.com/ansible/playbooks_conditionals.html#applying-when-to-roles-and-includes>?
 
Along with include_vars 
<http://docs.ansible.com/ansible/include_vars_module.html#include-vars-load-variables-from-files-dynamically-within-a-task>
 
I think you should be able to achieve the desired effect.

Something like the below:

---

- name: include_vars example 

  hosts: all

  tasks:

    - name: Debug hostname.

      debug:

        var: inventory_hostname

      # Different filenames with the same variables *should* override the 
variables for each instance of playbook execution.

      # But precedence is tricky and I've had trouble getting things like 
this to work in the past, so ymmv.
           - name: Include variables based on hostname.

      include_vars: "vars/{{ inventory_hostname }}.yml"

    - name: Print site name and port number.
             debug:

        msg: "My site {{ site_name }} is running on port {{ port_number }}."

...

# vim: ft=ansible:

Sorry if the formatting is a little wonky the code widget is a little weird 
sometimes.

Hope this helps, best of luck.

Alex



On Tuesday, October 18, 2016 at 12:02:43 PM UTC-7, Nick Tkach wrote:
>
> So, the general idea is I've got a playbook that has a set of "property" 
> files (yaml format).  Different filenames, but the variable names inside 
> are the same:
>
> group_vars/siteA.yml
> ---
> site_name: appA
> port: 8080
>
> group_vars/siteB.yml
> ---
> site_name: appB
> port: 8090
>
>
>
> and so on.  I want to run a task that does work using each of those in 
> turn like
>
> - name: print out the value of site_name and port for each of the 
> group_vars files
>   debug: msg="My site {{ site_name }} is on port {{ port }}"
>
>
>
> So you'd expect output like
>
> My site appA is on port 8080
> My site appB is on port 8090
>
> I'm not finding a way to get this result.  You can't apply a with_fileglob 
> to a task block so I'm not sure how to do something to *both* "reset" the 
> variables (something like var_files?) *and* do some kind of work with the 
> values from *that* file.  I'm assuming I'm missing something about how to 
> look at this?
>

-- 

-- 
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/60920ccc-85d9-4ee9-a8fb-685eaa431a99%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to