LoginSignup
1
1

More than 5 years have passed since last update.

inventoryファイルでグループ外ホストを指定する。

Posted at

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の修正で気になったのでメモでした。

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