ansible TIPS

How to create an empty file with Ansible?

- name: ensure file exists
  copy:
    content: ""
    dest: /etc/nologin
    force: no
    group: sys
    owner: root
    mode: 0555

https://stackoverflow.com/questions/28347717/how-to-create-an-empty-file-with-ansible

【Ansible】かゆいところに手が届く12のTips その1
https://qiita.com/Gin/items/653ae4d9a628334cf34b

inventory 変数で boolean "false" は False と書く

switch=False

Not all spellings of boolean "false" in inventory are interpreted as false by Jinja
https://github.com/ansible/ansible/issues/25784

ansible 変数の優先順位

https://qiita.com/gamisan9999/items/5ff5a7851c442fa3954d

つよい(確信)

  • extra vars
  • タスクのvars
  • ブロックのvars
  • ロールのvars/includeした変数ファイル
  • set_facts
  • 処理でregisterした変数
  • 処理内vars_filesで指定のファイルで定義された変数
  • 処理内vars_promptでプロンプトから渡された変数
  • 処理内のvarsで定義された変数
  • ファクト(setupで拾ってきた値)
  • Playbookで定義されたhost_vars
  • Playbookで定義されたgroup_vars
  • インベントリで定義されたhost_vars
  • インベントリで定義されたgroup_vars
  • インベントリで定義された変数
  • ロールのデフォルト(/roles/*/defaults/main.yml)

https://qiita.com/KeijiYONEDA/items/721407cbe418b3d532ed

ansible check_mode changed_when

- command: test -f /path_to/file
  check_mode: no
  changed_when: false
  register: _test_file
- some_module: hogehohe
  when: _test_file.rc = 1

https://dev.classmethod.jp/server-side/ansible/using_check_mode/

https://dev.classmethod.jp/server-side/ansible/ansible_playbook_with_idempotence/

- command: wp core is-installed --path=/var/www/html
  check_mode: no
  changed_when: false
  register: _check_wp_installation

wpがインストールされているか判定、checkモードでも実行、changedにしない