My playbook (test.yml
) is like below:
- hosts: localhost
connection: local
gather_facts: false
roles:
- env
environment:
AWS_ACCESS_KEY_ID: "{{ access }}"
tasks:
- debug:
msg: "Hello"
And I get following error:
TASK [env : Load VPC variables file] ******************************************************************************************************** fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'environment' has an invalid value, which appears to include a variable that is undefined. The error was: 'access' is undefined\n\nThe error appears to have been in '/var/yogesh/test/roles/env/tasks/main.yml': line 1, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Load VPC variables file\n ^ here\n"}
PLAY RECAP ********************************************************************************************************************************** localhost : ok=0 changed=0 unreachable=0
failed=1
My role (roles/env/tasks/main.yml
) is like below:
- name: Load VPC variables file
include_vars: "vault.yml"
This vault.yml
looks like:
access: 1234
test.yml
and vault.yml
are in the same directory.
Now if I change playbook test.yml
like below, somehow it works.
- hosts: localhost
connection: local
gather_facts: false
vars_files:
- vault.yml
environment:
AWS_ACCESS_KEY_ID: "{{ access }}"
tasks:
- debug:
msg: "Hello"
I am not sure why is this happening. Can someone please shed light on this? Do we have to declare vault files in vars_files only? Is there any better/best practice alternative?
Ansible version: 2.3.0.0