LoginSignup
1
2

More than 5 years have passed since last update.

Ansibleでa2enmod(冪等性)

Last updated at Posted at 2014-11-24

@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の結果を変数で受け取る
1
2
2

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
1
2