我的样本playbook(适用于ansible 2.1)如下:
---
# This is sample playbook.
- name: add sample_role
hosts: '{{ target }}'
become: true
become_user: root
roles:
- sample role
当我运行它时,一切都很好:
ansible-playbook -i staging test_playbook.yml --extra-vars "target=192.168.15.29"
如何省略目标?
我尝试了以下方法:
hosts: '{{ target | default(all) }}'
或者
hosts: '{{ target | default(hostvars) }}'
然后运行:
ansible-playbook -i staging test_playbook.yml
但是不幸的是:
错误!'all'未定义
或者:
错误!'hostvars'未定义
all
对我有效:hosts: '{{ target | default("all") }}'
- A K'{{ target | default("all") }}'
有效?特别是,为什么|
符号有效?这在哪里有记录?我有一个用例,我想将多个默认组设置为目标。 - alex