I have a problem checking if a file exists:
- name: Check if ssh key exists
stat: path= "/config/clients/ssh_keys/daniel_nanboe.pub"
register: exista
- debug: var=exista
- fail:
msg: Stop
The file exists but the stat returns false:
“exista”: {
“changed”: false,
“failed”: false,
“stat”: {
“exists”: false
}
}
that exact task errors because of the space after "path=" - I think
that's a typo on your part?
Thanks I have removed that but the result is the same when I debug de var stat is false:
ok: => {
“exista”: {
“changed”: false,
“failed”: false,
“stat”: {
“exists”: false
}
}
}
It could still be a permissions issue, for instance if the ansible user has different rights than whatever you did manually that caused you to believe that the file is there.
Which leads to the question: how did you establish that the file is actually there?
I just realised that I am stupid
The file was on the computer where I was running the ansible script not on the target server. What I needed to do was to run the check locally
`
- name: Check if ssh key exists
local_action: stat path=“/config/clients/ssh_keys/daniel_nanboe.pub”
register: exista
- debug: var=exista
- fail:
msg: Stop
`