Sorry I can't help with reading the file but this is how I am setting environment variables to use with a shell line
vars_prompt:
- name: ABC_environment
prompt: "Enter live or preprod to set environment"
private: no
when: ABC_environment is undefined
- name: ABC_password
prompt: "Enter the ABC Encryption key"
private: yes
when: ABC_password is undefined
environment:
ABCENV: "{{ ABC_environment }}"
ABCPWD: "{{ ABC_password }}"
- name: install ABC file
shell: unzip -P ${ABCPWD} -o -d/application /tmp/ABC_files.zip ABC_${ABCENV}_application.file
shell: sudo -u xyz install -o xyz -g xyz -m 550 /application/ABC_${ABCENV}_application /application/application.file
Hope this helps..