为什么我不能访问Ansible中通过文件加载的变量?

时间:2017-07-09 07:39:31

标签: variables ansible

为什么我不能从Ansible任务中访问这些Ansible文件变量?

我已尝试public class porder_adapter extends ArrayAdapter<POrder> { private List<POrder> items; public porder_adapter(Context context, int resource, List<POrder> items) { super(context, resource, items); this.items = items; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView != null) { return convertView; } else{ View v = convertView; TextView modelNo = null; LayoutInflater vi; vi = LayoutInflater.from(getContext()); v = vi.inflate(R.layout.layout_model, null); modelNo = (TextView) v.findViewById(R.id.layout_model_Model); POrder p = items.get(position); if (p != null) { if (modelNo != null) modelNo.setText("" + p.getModelNo()); } return v; } } public int getViewTypeCount() { return getCount(); } public int getItemViewType(int position) { return position; } } 以及调用vars_filesglobal.varname

的组合
global[varname]

- hosts: localhost gather_facts: True remote_user: root - include_vars: site_vars.yml tasks: - digital_ocean: state: present command: droplet unique_name: yes name: do_16_04_common api_token: "{{HOST_PROVIDER}}"

global_vars.yml

错误:

  

致命:[localhost]:失败! =&GT; {“failed”:true,“msg”:“ERROR!'ansible.parsing.yaml.objects.AnsibleUnicode object'没有属性'WORKER_TAG_PREFIX'”}

1 个答案:

答案 0 :(得分:2)

首先,你的vars文件坏了 - 它需要:和值之间的空格(在这个例子中你不需要字符串的引号):

global:
  WORKER_TAG_PREFIX: dev
  HOST_PROVIDER: heroku-prod

以上是包含错误的原因,但是代码也有语法错误,应首先抛出:

在游戏级别包含vars文件的正确语法是定义包含文件列表的vars_files key

- hosts: localhost
  gather_facts: True
  remote_user: root
  vars_files:
    - site_vars.yml
  tasks:
    # ...

另一方面,include_vars是任务的模块(动作)名称。

如果您想使用它,您应该将其添加到任务列表中:

- hosts: localhost
  gather_facts: True
  remote_user: root
  tasks:
    - include_vars: site_vars.yml