DEV Community

Abid Ali
Abid Ali

Posted on

Certificate Renewal with Ansible on Multiple Linux Server

Hi,

I'm wirting a playbook in which i want to update Certificate used with websites but now i'm stuck on Debug out how i can fiter desired output.

---
- hosts: repo1
  become: true
  tasks:
    - name: Papulate Service Facts
      service_facts:
    - name: See the Service <httpd> facts as they are"
      debug:
        msg: "{{ ansible_facts.services['httpd.service'].state }}"
      register: http_service_status
    - name: Debug output
      debug:
        var: http_service_status
    - name: Check website path details
      shell: httpd -S | grep -e "port 443" | awk '{print $NF}' | awk -F ":" '{print $1}' | tr "(" " " |  awk '{ gsub(/ /,""); print }'
      register: path_output
      when: http_service_status.msg == "running"
    - name: Print path details
      debug:
        var: path_output.stdout_lines
    - name: Fetch SSL certificate path details
      shell: |
        grep -i -r SSLCertificate "{{ item }}" | grep '.crt' | awk '{print $NF}'
      with_items: "{{ path_output.stdout_lines }}"
      ignore_errors: true
      register: cert_path
    - name: Print path details
      debug:
        var: cert_path
    - name: Get subject of SSL
      shell: openssl x509 -noout -subject -in "{{ item.stdout_lines }}"
      with_items: "{{ cert_path.results }}"
      loop_control:
        label: "{{ item.stdout_lines }}"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)