我的示例剧本(适用于 ansible 2.1)是:
---
# This is sample playbook.
- name: add sample_role
hosts: '{{ target }}'
become: true
become_user: root
roles:
- sample role
Run Code Online (Sandbox Code Playgroud)
当我运行它时,一切都很好:
ansible-playbook -i staging test_playbook.yml --extra-vars "target=192.168.15.29"
Run Code Online (Sandbox Code Playgroud)
我怎样才能省略目标?
我尝试过这样的事情:
hosts: '{{ target | default(all) }}'
Run Code Online (Sandbox Code Playgroud)
或者
hosts: '{{ target | default(hostvars) }}'
Run Code Online (Sandbox Code Playgroud)
然后运行:
ansible-playbook -i staging test_playbook.yml
Run Code Online (Sandbox Code Playgroud)
, 但不幸的是:
错误!“全部”未定义
或者:
错误!“hostvars”未定义
ansible ×1