cupcake
(cupcake)
1
ansible core 2.1
When using win_lineinfile module and the create: yes
option it seems it should create a new file. it fails the same as if create:yes is not specified.
If dest doesn’t exist it fails. Guessing I am doing something wrong?
If you run with -vvvvv what error message do you see?
Does your ansible user have permission to write to c:\temp\ansible-windows.log ?
Hope this helps,
Jon
cupcake
(cupcake)
3
The user account is a local admin account with perm to the c:\temp folder. Error is:
`
fatal: [winserver1.foo.com]: FAILED! => {
“changed”: false,
“failed”: true,
“invocation”: {
“module_name”: “win_lineinfile”
},
“msg”: “Destination c:\temp\ansible-windows_base.log does not exist !”
}
`
If the file exists it works:
`
changed: [winserver1.foo.com] => {
“backup”: “”,
“changed”: true,
“encoding”: “utf-8”,
“invocation”: {
“module_name”: “win_lineinfile”
},
“msg”: “line added”
}
`
And if i create a task to create the file ahead of time all is OK
`
- hosts: all
tasks:
- name: create file
win_file:
path: ‘c:\temp\ansible-windows_base.log’
state: touch
- name: win_lineinfile test
win_lineinfile:
dest: ‘c:\temp\ansible-windows_base.log’
create: true
line: ‘test-{{ ansible_hostname }}-{{ ansible_date_time.iso8601 }}’
regexp: ‘test-{{ ansible_hostname }}-’
state: present
`
And re-run:
`
TASK [create file] ******
changed: [winserver1.foo.com] => { “changed”: true, “invocation”: { “module_name”: “win_file” } }
TASK [win_lineinfile test] ******
changed: [winserver1.foo.com] => { “backup”: “”, “changed”: true, “encoding”: “utf-16”, “invocation”: { “module_name”: “win_lineinfile” }, “msg”: “line added” }
`
I’ve also upgrade to 2.2.1.0 and getting the same. Since the linux module will create a new file I’m assuming something is funky with the windows one.