If you have variables defined centrally, use them via vars_files,
group_vars, or whatever, and you don't need to copy them to local facts *at
all*.

Local facts are there for when an administrator wants to make the mortals
who use a system be able to configure it basically.

(Or it's a shortcut to avoid writing a fact module, in some cases, though
fact modules are better-er)

So ultimately I want to step back and understand the use case a bit rather
than working through your questions above - though they aren't bad
questions, I think we'd be leading you a bit astray - maybe.

I could be wrong.




On Thu, Jul 24, 2014 at 11:17 AM, Marcin Prączko <[email protected]>
wrote:

> Hi,
>
> I struggle with some issue with variables definition which I am not
> totally understand and can't find help in ansible docs.
>
> I am trying to have nice variables structure and save it as json file
> (re-use as local facts).
>
> So I have *groups_vars* file:
> g_core_vars:
>   version : "0.1.0"
>   varinfo:
>     vi_name    : "core_vars"
>     vi_vartype : "groupvars-all"
>   vars:
>     status : "non-prod"
>     env    : "develop"
>     lob    : "none"
>     product: "none"
>     prole  : "other"
>     roles:
>       - web
>
>
> Now I would like to create variable based on above values:
> For example:
> g_core_nagios_filename: '{{ g_core_vars.vars.env }}-{{
> g_core_vars.vars.product }}'.cfg
>
> However I am gettig error on ansible:
> ERROR: One or more undefined variables: 'dict object' has no attribute:
> 'vars'.
>
> My goal is no that I can write this variabe 'g_core_vars' to json with
> 'copy' module:
> - name: Write g_core_vars variables to local facts
>   copy: content="{{ g_core_vars }}" dest=/etc/ansible/facts.d/{{
> g_core_vars.varinfo.vi_name }}.fact
>         owner=root group=root mode=0644
>
>
> *Summary:*
> - How I can use defined variables which used previous variables names and
> can be saved as json in one task?
> - Not quite undertand this principle that I have to define each variable
> sepearatly.
>
> # Variables files.
> var01: 'value01'
> var02: 'value02'
>
> somevars1:
>   v01: '{{ var01 }}'
>   v02: '{{ var02 }}'
>
> # Will work
> somevars2: '{{ var01 }}-{{ var02 }}'
>
> # Will not work
> somevars2: '{{ somevars1.var01 }}'
>
>
> Please advice.
>
> Best regards.
> Marcin
>
>
>
>  --
> 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/1d3b58f6-aa1f-4bd2-8f65-38bbef00aac7%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/1d3b58f6-aa1f-4bd2-8f65-38bbef00aac7%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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/CA%2BnsWgz%2BYJD3uap9QsXspQbYf9rykgg7SrfZK8fDxOat3Bg9qQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to