LoginSignup
1
6

More than 5 years have passed since last update.

playbook テンプレート

Last updated at Posted at 2017-03-10

自分で作ったplaybookを公開する.

プロジェクト単位に共通化したもの

  • handler
    プロジェクトのhandlerを /path/to/pj/handlers/main.yml に集約

  • roles
    プロジェクトのroles を /path/to/pj/roles/

仕様

  • tasksを開始する前に,ターゲットのホストネームとインベントリに書いてある名前と照らし合わせて,一致しなければ,止まる
  • .ansible_build_is_done ファイルが存在したら,止まる

playbook中に,冪等性持っていないタスクがあるため, playbook単位に 二度と実行させない.

  • playbook最後まで行けたら,.ansible_build_is_done ファイル作成する
  • rolesを実行条件によって,グルーピングする
---
- hosts: hogehoge
  become: true

  handlers:
    - include: handlers/main.yml

  pre_tasks:
    - name: check target hostname
      local_action: command test {{ inventory_hostname }} = {{ ansible_hostname }}
      become: false
      tags: always

  tasks:
    - name: check - is ansible build done
      command: test ! -e .ansible_build_is_done
      become: false

    - block:
       - name: build foo1
         include_role:
           name: foo1
       - name: build foo2
         include_role:
           name: foo2
       - name: build foo3
         include_role:
           name: foo3
      when:
        - ansible_distribution == 'CentOS'
        - ansible_distribution_major_version == '7'

    - name: install foo4
      include_role:
        name: foo4
      when:
        - foo4_enabled == 'yes'
        - ansible_distribution == 'CentOS'
        - ansible_distribution_major_version == '7'
      tags: 1.2.0

    - name: flag - ansible build is done.
      file: path=.ansible_build_is_done mode=0600 state=touch
      become: false
1
6
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
1
6