Ansible - 无法使变量起作用

时间:2017-04-25 20:50:21

标签: ansible

我正在测试ansible中的variable功能以及include_varswith_first_found

我的剧本是

---
- name: Load Variables from files.
  include_vars: "{{ item }}"
  with_first_found:
    - "a.yml"
    - "b.yml"
    - "default.yml"

- name: another play
  hosts: all
  tasks:
    - debug: msg="hello {{ http_port }}"

但是当我运行这个时,我得到了错误,

# ansible-playbook -i inventory/plat-inventory test.yaml 
ERROR! 'with_first_found' is not a valid attribute for a Play

The error appears to have been in '/root/config-3.0.98/ansible/test.yaml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Load Variables from files.
  ^ here

default.yml声明:

http_port: 80

我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

据我所知,include_vars应该是一项任务,its documentation

中的示例

类似

- name: playbook
  hosts: somehosts
  gather_facts: false
  tasks:
    - name: "add some vars"
      include_vars: somefile.yml

但是,那些变量在其他剧本中可能无法获得。