@hnakamur さんにa2enmodが出来るAnsibleモジュールがあるのを教えて頂きました!こちらを使いましょう!
a2enmod はapache2_module - enables/disables a module of the Apache2 webserver — Ansible DocumentationというAnsibleモジュールが用意されているのでこちらがお勧めですよ。
apache2_module - enables/disables a module of the Apache2 webserver — Ansible Documentation
ググっても出てこなかったので。こんな感じでやるとchangedの数が増えなくていい。
- name: Apache2 モジュール有効化
action: command a2enmod {{item}}
tags: apache2
register: result
changed_when: "'already enabled' not in result.stdout"
with_items:
- expires
- headers
Ansibleで冪等性を担保した形でa2enmodを叩くのが見当たらなかったので、調べた。
-
changed_when
てのが実行結果がchangedかどうかを見る -
register
でmoduleの結果を変数で受け取る