LoginSignup
2
4

More than 5 years have passed since last update.

Ansibleでtd-agentのプラグインを管理するRole

Last updated at Posted at 2017-03-14

td-agentのプラグインはtd-agent-gemで導入しますが、Ansibleにはそのモジュールがありません。

というわけでcommandモジュールで実装します。幸いtd-agent-gemはすでに導入済みのプラグインについて再度実行しても問題ないので、changed_when: noにしてchangedがカウントされないようにします。

また、バージョン指定・未指定でも動くようにします。

念のため、コマンドの終了コードを見てretryをかけます。

ディレクトリ構成
├── roles
│   └── td-agent_plugin
│       └── tasks
│           └── main.yml
├── site.yml
└── vars
    └── vars.yml

whenでvarsが未定義の場合と--check時には実行されないようにします。

roles/td-agent_plugin/tasks/main.yml
---
- name: install td-agent plugin
  command: >-
    /usr/sbin/td-agent-gem install
    {{ item.name }}
    {% if item.version is defined %}
    -v {{ item.version }}
    {% endif %}
    --no-ri --no-rdoc
  changed_when: no
  become: yes
  register: result
  until: result.rc == 0
  retries: 5
  delay: 10
  with_items: "{{ my_vars.middlewares.td_agent.configs.plugin.params }}"
  when: my_vars.middlewares.td_agent.configs.plugin is defined and not ansible_check_mode
vars/vars.yml
---
my_vars:
  middlewares:
    td_agent:
      configs:
        plugin:
          params:
            - name: fluent-plugin-config-expander
            - name: fluent-plugin-secure-forward
              version: 0.3.3dev2
site.yml
---
- hosts: targethost
  roles:
    - role: td-agent_plugin

  vars_files:
    - ./vars/vars.yml
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