Unable to load variable from include_vars into my playbook

15 vistas
Ir al primer mensaje no leído

Shifa Shaikh

no leída,
24 feb 2020, 1:17:48 p.m.24/2/2020
para Ansible Project
I have a playbook where I load a variable file 

cat vars/BASE.yaml


EXCLUDE_front
: value1
EXCLUDE_back
: value2


I run my test.yml playbook using this command:

ansible-playbook test.yml -e Layer="back" -e base_folder="/tmp"


- name: Load a variable file"
  include_vars:
    file: "
vars/BASE.yaml"

- name: Collect data
  shell: "
cd {{ base_folder }} && find . -type d \\( -name 'BACKUP' -o -name 'vars[EXCLUDE_{{ Layer }}]' \\) -prune -o -type f -exec cksum {} + | awk '{$1=\"\"}1'"
  register: outputfiles

I also tried 

  shell: "cd {{ base_folder }} && find . -type d \\( -name 'BACKUP' -o -name 'vars[EXCLUDE_ + Layer ]' \\) -prune -o -type f -exec cksum {} + | awk '{$1=\"\"}1'"

and

  shell: "cd {{ base_folder }} && find . -type d \\( -name 'BACKUP' -o -name 'vars[EXCLUDE_ ~ Layer ]' \\) -prune -o -type f -exec cksum {} + | awk '{$1=\"\"}1'"

however,  instead of loading value1 or value2, I get the below nature of error:

"The task includes an option with an undefined variable. The error was: 'EXCLUDE_' is undefined\n\nT

Can you please suggest what is wrong with my playbook? 

Dick Visser

no leída,
24 feb 2020, 3:53:17 p.m.24/2/2020
para ansible...@googlegroups.com
You can’t resolve variables with names that contain variables themselves. 
Instead, use a lookup:

Also try to use the args: chdir option instead of doing &&, see 



--
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 view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/f76a6376-0ac3-4724-9bb9-6fc54bd69610%40googlegroups.com.
--
Sent from a mobile device - please excuse the brevity, spelling and punctuation.

Stefan Hornburg (Racke)

no leída,
25 feb 2020, 1:43:18 p.m.25/2/2020
para ansible...@googlegroups.com
On 2/24/20 9:52 PM, Dick Visser wrote:
> You can’t resolve variables with names that contain variables themselves. 
> Instead, use a lookup:
>
> https://docs.ansible.com/ansible/latest/plugins/lookup/vars.html
>
> Also try to use the args: chdir option instead of doing &&, see 
> https://docs.ansible.com/ansible/latest/modules/shell_module.html
>

"{{ vars['EXCLUDE_' + Layer] }}" should work though.

Regards
Racke

>
>
> On Mon, 24 Feb 2020 at 19:18, Shifa Shaikh <shif...@gmail.com <mailto:shif...@gmail.com>> wrote:
>
> I have a playbook where I load a variable file 
>
> |
> cat vars/BASE.yaml
>
>
> EXCLUDE_front:value1
> EXCLUDE_back:value2
> |
>
>
> I run my test.yml playbook using this command:
>
> |
> ansible-playbook test.yml -e Layer="back"-e base_folder="/tmp"
>
>
> -name:Loada variable file"
>   include_vars:
>     file: "vars/BASE.yaml"
>
> - name: Collect data
>   shell: "cd {{base_folder }}&&find .-type d \\(-name 'BACKUP'-o -name 'vars[EXCLUDE_{{ Layer }}]'\\)-prune -o -type
> f -execcksum {}+|awk '{$1=\"\"}1'"
>   register: outputfiles
> |
>
> I also tried 
>
> |
>   shell:"cd {{ base_folder }} && find . -type d \\( -name 'BACKUP' -o -name 'vars[EXCLUDE_ + Layer ]' \\) -prune -o
> -type f -exec cksum {} + | awk '{$1=\"\"}1'"
> |
>
> and
>
> |
>   shell:"cd {{ base_folder }} && find . -type d \\( -name 'BACKUP' -o -name 'vars[EXCLUDE_ ~ Layer ]' \\) -prune -o
> -type f -exec cksum {} + | awk '{$1=\"\"}1'"
> |
>
> however,  instead of loading value1 or value2, I get the below nature of error:
>
> "The task includes an option with an undefined variable. The error was: 'EXCLUDE_' is undefined\n\nT
>
>
> Can you please suggest what is wrong with my playbook?
>
> --
> 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 <mailto:ansible-proje...@googlegroups.com>.
> <https://groups.google.com/d/msgid/ansible-project/f76a6376-0ac3-4724-9bb9-6fc54bd69610%40googlegroups.com?utm_medium=email&utm_source=footer>.
>
> --
> Sent from a mobile device - please excuse the brevity, spelling and punctuation.
>
> --
> 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 <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CAL8fbwOiQArWXn2N4pc1vW-YmAZ09dNn3cN2yy_ZgWVbh6ieEw%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CAL8fbwOiQArWXn2N4pc1vW-YmAZ09dNn3cN2yy_ZgWVbh6ieEw%40mail.gmail.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Shifa Shaikh

no leída,
26 feb 2020, 2:54:20 a.m.26/2/2020
para ansible...@googlegroups.com
It's works. Thank you Stefen

To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/11ef6e0e-fb43-ddd0-a7e7-64ed0510e782%40linuxia.de.
Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos