LoginSignup
25
25

More than 5 years have passed since last update.

Ansible when 分岐 inventory_hostname

Last updated at Posted at 2015-01-25

インベントリファイル中身↓


[testgroup1]
testhost1
testhost2

[testgroup2]
testhost3
testhost4

[testgroup]
testhost1
testhost2
testhost3
testhost4

プレイブック自体は
host: testgroup
で実行したとして

test1だけコンフィグファイルを分けたいとかって時、
こういう書き方ができるんすねー


## ホスト名がtesthost1だったら実行
- copy: src=usr/local/abc.conf dest=/usr/local/httpd.conf mode=644
when: inventory_hostname == 'testhost1'


これだとtesthost1だと実行される

グループで分ける需要が多そう


## グループ名がtestgroup1のホストだったら実行
- copy: src=usr/local/abc.conf dest=/usr/local/httpd.conf mode=644
when: inventory_hostname in groups['testgroup1']


これだとtestgroup1のtesthost1,testhost2で実行される

25
25
3

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