I’m writing a playbook and have never tried to do this particular thing I’m doing.
I have 500 host computers - all RHEL8
Using ansible version: ansible [core 2.16.3]
From a server, I’m configuring a playbook to reach out to all 500 computers and…
- Determine if a $HOSTNAME.key file exists
- if It doesn’t, it will scp the file from the server (which is a Cert Authority server)
Ultimately the goal is to check for the existence of a $HOSTNAME.key and .crt file, and if they don’t exist, create them, and copy them to the remote host. For reasons of revocation, we definitely don’t want a playbook to create certs every time, when they definitely do exist.
I tried this with just a plain file and it worked fine. I created “file1” in /tmp on the CA. I ran the playbook, it didn’t find file1 on my one host (only testing with 1 host for now), so it copied the file over to /tmp on the host.
Then I changed the playbook to the actual file I want to check for. The path statement is written like this:
tasks:
-
name: Check for $HOSTNAME.key
stat:
path: /tmp/$HOSTNAME.key
register: key -
name: Report if file exists
debug:
msg: “the file exists”
when: key.stat.exists == True
The problem is that the file does exist, but it keeps reporting that it’s skipping the debug/msg portion, finding it to be False. Yet the file is in /tmp on the host and I’ve even used chmod 777 in case of a permissions issue.
I can’t see what I’m doing wrong. Any ideas anyone? Thanks!