I am trying to figure out how to get a list of .crt
files from one of our web servers and check the expiration date of these certification files (actually check if these certs are valid within a time range). What I have so far is the following .yml
playbook code:
#
# simple playbook to check certificates expiration date
- name: find cerfication files & expiration dates
hosts: 10.0.1.120
gather_facts: false
tasks:
- name: Find cert files under /etc/pki/tls/certs
find:
paths: /etc/pki/tls/certs
file_type: file
patterns: "*.crt"
recurse: yes
excludes: "localhost.crt"
register: find_result
- name: check validity
openssl_certificate_info:
path: "{{ item.path }}"
valid_at:
point_1: "+1w"
point_2: "+10w"
register: result
loop: "{{ find_result.files|flatten(levels=1) }}"
#- name: validate
#assert:
#that:
#- result.valid_at.point_1
#- result.valid_at.point_2
- debug: msg= "{{ result }}"
The result of the above debug msg
is the following:
TASK [debug] ****************************************************************************
ok: [10.0.1.120] => {
"msg": ""
}
I left the assert
module with comments, so can also check the other output that I was trying to get by using the assert
module and get a passed/failed message for each result (point_1 & point_2).
If I give the .crt
path hardcoded and with no loop, I get the exams that I am looking for, but when I try with the loop
command, assert
module is not running as expected and I am getting a dict object
error, like the following one:
fatal: [10.0.1.120]: FAILED! => {"msg": "The conditional check 'result.valid_at.point_1' failed. The error was: error while evaluating conditional (result.valid_at.point_1): 'dict object' has no attribute 'valid_at'"}
Extra info regarding my ansible hosting server:
- Server distro: CentOS-7
- Ansible version: 2.8.1
So guys, any suggestions on how to get this loop run properly in order the get the passed/failed messages that I want for every .crt
file that can be found under the /etc/pki/tls/certs
path (except the localhost.crt)?