LoginSignup
2
4

More than 3 years have passed since last update.

Ansibleでサーバ証明書情報のレポートを作成してみた

Posted at

Ansibleでサーバ証明書の情報を取得してレポート化できたら便利かなと思い作ってみました。

Ansible Server Certificate Report Generator

https://github.com/sky-joker/ansible-server-certificate-report-generator

環境

項目 バージョン
CentOS 7.6

使い方

クローン

リポジトリをクローンします。

[root@b3b24c5352f8 ~]# git clone https://github.com/sky-joker/ansible-server-certificate-report-generator.git

インストール

ansibleと必要なpythonモジュールをインストールします。

[root@b3b24c5352f8 ~]# cd ansible-server-certificate-report-generator/
[root@b3b24c5352f8 ansible-server-certificate-report-generator]# pip install -r requirements.txt

Playbookの作成

Playbookを作成します。

[root@b3b24c5352f8 ansible-server-certificate-report-generator]# vi main.yml

サーバ証明書の情報を取得したいサーバのFQDNやIPアドレスを servers 変数に追加します。

---
- name: Generate of server certificate report
  hosts: localhost
  gather_facts: no
  vars:
    servers:
      - www.example.com
      - www.yahoo.co.jp
      - github.com
  tasks:
    - name: Get certificate information from server.
      server_certificate_info:
        server: "{{ item }}"
      loop: "{{ servers }}"
      register: certificate_result

    - name: Generate report.
      template:
        src: templates/server_certificate_report.j2
        dest: server_certificate_report.html

Proxyを使う場合は以下のようにオプションを追加します。

---
- name: Generate of server certificate report
  hosts: localhost
  gather_facts: no
  vars:
    servers:
      - www.example.com
      - www.yahoo.co.jp
      - github.com
  tasks:
    - name: Get certificate information from server.
      server_certificate_info:
        server: "{{ item }}"
        proxy_host: 192.168.1.1
        proxy_port: 3128 # defaultは 8080
      loop: "{{ servers }}"
      register: certificate_result

    - name: Generate report.
      template:
        src: templates/server_certificate_report.j2
        dest: server_certificate_report.html

Playbookの実行

Playbookを実行します。

[root@b3b24c5352f8 ansible-server-certificate-report-generator]# ansible-playbook main.yml
 [WARNING]: No inventory was parsed, only implicit localhost is available

 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'


PLAY [Generate of server certificate report] *******************************************************************************************************************************

TASK [Get certificate information from server.] ****************************************************************************************************************************
ok: [localhost] => (item=www.example.com)
ok: [localhost] => (item=www.yahoo.co.jp)
ok: [localhost] => (item=github.com)

TASK [Generate report.] ****************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP *****************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

レポート確認

問題なく実行が完了すれば、Playbookを実行したディレクトリに server_certificate_report.html が作成されているのでブラウザで開きます。

スクリーンショット 2019-08-04 2.35.18.png

こんな感じでレポートが作成できます :)
ほかの使い方としては、証明書の更新を自動化した後にきちんと更新されているか確かめるテストとしても使うことができそうですね!

みんなでハッピーオートメーション!

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4