ansiblesyntax-errorruntime-error

Ansible error: The task includes an option with an undefined variable


Below is how my complete helpA.yml playbook looks like:

- hosts: localhost

  tasks:
   - name: "Construct File Path {{ inventory_hostname }} before Deployment."
     tags: validate
     include_vars:
       file: "{{ item }}"
     with_fileglob:
        - "vars/{{ Layer }}_*.yaml"

   - name: "set_fact"
     tags: validate
     set_fact:
       fpath_APP: "{{ fpath_APP + [ BASEPATH ~ '/' ~ vars[item.split('.')[1]] ~ '/' ~ item | basename ] }}"
     when: Layer == 'APP'
     with_items:
       - "{{ Source_Filenames.split(',') }}"
     vars:
       fpath_APP: []

   - debug: var=fpath_{{ Layer }}

I'm getting the below syntax error running the yml.

$ ansible-playbook /app/helpA.yml --tags validate -e "Source_Filenames=/tmp/logs/filename1.src,/tmp/logs/33211.sql,/app/Jenkins/file1.mrt Layer=APP" [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [localhost]


TASK [Construct File Path localhost before Deployment.] ************************************************************************************************* ok: [localhost] => (item=/app/vars/APP_BASE_vars.yaml)

TASK [set_fact] *************************************************************************************************************************************************************** fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute u'src'\n\nThe error appears to be in '/app/helpA.yml': line 12, 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 - name: \"set_fact\"\n ^ here\n"}

PLAY RECAP ******************************************************************************************************************************************************************** localhost : ok=1 changed=0 unreachable=0
failed=1 skipped=0 rescued=0 ignored=0

I'm on the latest version on of ansible and python 2.7.5


Solution

  • Basically you are looking up the dict vars for a key src (which is your file extension), and it doesn't exist – Credits: Matt P

    Also you don't provide an inventory which causes:

     [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'