set_fact undefined variable issue when concat string to itself.

22 views
Skip to first unread message

Shifa Shaikh

unread,
Feb 26, 2020, 1:30:42 AM2/26/20
to Ansible Project
I need to set_fact variable and contact to itself a list of items as below:

    - set_fact:
        excludefolders
: "{{ excludefolders + ' -o -name ' + item | default('') }}"
      with_items
: "{{ lookup('vars', 'MY_' + Layer).split(',') }}"


Getting error:

FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'excludefolders' is undefined\n\nThe error appears to be in '/app/test.yml': line 86, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n   - set_fact:\n     ^ here\n"}

Is it neccessary to defined another set_fact before like below or is there a better solution to the issue ?

    - set_fact:
        excludefolders
: ""


   
- set_fact:
        excludefolders
: "{{ excludefolders + ' -o -name ' + item | default('') }}"
      with_items
: "{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"




Abhijeet Kasurde

unread,
Feb 26, 2020, 1:39:19 AM2/26/20
to ansible...@googlegroups.com
You can try this -

    - set_fact:
        excludefolders: "{{ excludefolders | default('') + ' -o -name ' + item | default('') }}"

      with_items: "{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"
--
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/3c491483-c408-4176-98dd-09a3bed1b47e%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

Shifa Shaikh

unread,
Feb 26, 2020, 4:21:30 AM2/26/20
to Ansible Project
It helped. Thank you @Abhijeet


On Wednesday, February 26, 2020 at 12:09:19 PM UTC+5:30, Abhijeet Kasurde wrote:
You can try this -

    - set_fact:
        excludefolders: "{{ excludefolders | default('') + ' -o -name ' + item | default('') }}"
      with_items: "{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"

On Wed, Feb 26, 2020 at 12:00 PM Shifa Shaikh <shif...@gmail.com> wrote:
I need to set_fact variable and contact to itself a list of items as below:

    - set_fact:
        excludefolders
: "{{ excludefolders + ' -o -name ' + item | default('') }}"
      with_items
: "{{ lookup('vars', 'MY_' + Layer).split(',') }}"


Getting error:

FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'excludefolders' is undefined\n\nThe error appears to be in '/app/test.yml': line 86, column 6, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n   - set_fact:\n     ^ here\n"}

Is it neccessary to defined another set_fact before like below or is there a better solution to the issue ?

    - set_fact:
        excludefolders
: ""


   
- set_fact:
        excludefolders
: "{{ excludefolders + ' -o -name ' + item | default('') }}"
      with_items
: "{{ lookup('vars', 'EXCLUDE_' + Layer).split(',') }}"




--
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...@googlegroups.com.


--
Thanks,
Abhijeet Kasurde
Reply all
Reply to author
Forward
0 new messages