ansible-playbook
実行時のinventoryファイルでグループ外のホストを対象する方法です。
inventoryファイルは以下のものを使用します。
# http://docs.ansible.com/ansible/intro_inventory.html
mail.example.com #これ。playbookのhostsでallを指定すれば対象になるが…。
[webservers] #いつも使う
foo.example.com
bar.example.com
[dbservers]
one.example.com
two.example.com
three.example.com
グループ外のホストを指定するには、playbookのhostsでそのままホストを指定します。
site.yml
- name: Ansible-Sample-TDD
hosts: mail.example.com #そのままホストを指定する。
user: root
roles:
- nginx
- mariadb
--list-tasks
を付けて実行してみると、対象になっています。
$ ansible-playbook site.yml -i hosts --list-hosts
playbook: site.yml
play #1 (Ansible-Sample-TDD): host count=1
mail.example.com
なお、この場合でも(当然ながら)Inventoryファイル指定を外すと実行できません。
$ ansible-playbook site.yml --list-hosts
ERROR: Unable to find an inventory file, specify one with -i ?
Ansible » Docs » Patternsに(微妙に)書いてあるのだけど、自作gemの修正で気になったのでメモでした。