質問
現在のプレイブックのホストが特定のグループにのホストが属していない場合にのみ、Ansibleタスクを実行できます。半疑似コードで:
- name: my command
command: echo stuff
when: "if {{ ansible_hostname }} not in {{ ansible_current_groups }}"
.
どうすればいいですか?
解決
これを行うもう1つの方法は次のとおりです。
- name: my command
command: echo stuff
when: "'groupname' not in group_names"
.
group_names
は、ここに記載されているようなマジック変数です。
group_namesは、現在のホストがin in inにあるすべてのグループのリスト(配列)です。
他のヒント
group_vars/
にあるVARSファイルで、またはこのようなhostsファイルに直接設定できます。
[vagrant:vars]
test_var=true
[location-1]
192.168.33.10 hostname=apollo
[location-2]
192.168.33.20 hostname=zeus
[vagrant:children]
location-1
location-2
.
とこのようなタスクの実行:
- name: "test"
command: "echo {{test_var}}"
when: test_var is defined and test_var
. 所属していません StackOverflow