3

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

4
  • 2
    Are you able to share the contents of /app/vars/APP_BASE_vars.yaml? This would help to isolate the problem. Basically you are looking up the dict vars for a key src (which is your file extension), and it doesn't exist Commented Aug 20, 2019 at 22:11
  • Here are the contents [has only one line] of /app/vars/APP_BASE_vars.yaml BASEPATH: /app/1090/BC10.2/app/cust/01 Commented Aug 20, 2019 at 22:14
  • 1
    Yep ok .. so the problem is as I stated above, but I'm not clear on what you are trying to achieve. What is your expectation for the final contents of the variable fpath_APP? Commented Aug 20, 2019 at 22:38
  • Rightly pointed .....Putting src variable in the vars file resolves the issue. Thank you @Matt P Commented Aug 21, 2019 at 3:23

1 Answer 1

1

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'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.