Reputation: 11
I'm trying to create a file on the target server using Ansible.
I would like to get the path from the env variable on the target server.
The code is:
- name: Create a file
win_file:
path: ansible_env.CONFIG_HOME\conf\xyz.txt
state: file
The error I'm receiving is:
"changed": false,
"msg": "path ansible_env.CONFIG_HOME\conf\xyz.txt will not be created"
Upvotes: 1
Views: 378
Reputation: 5237
There are two issues here.
Firstly, since you are trying to use an environment variable, you need braces {{ }}
to interpolate the value.
Secondly, have a close read of the docs for win_file
where it talks about the way state
behaves:
If
file
, the file will NOT be created if it does not existIf
touch
, an empty file will be created if the path does not exist
Taking into consideration the above, the following should work for you:
- name: Create a file
win_file:
path: "{{ ansible_env.CONFIG_HOME }}\conf\xyz.txt"
state: touch
Upvotes: 1