这是使用Ansible 2.7的错误
我正在尝试将包含vars的文件包含在我的具有多个import_playbooks的剧本中。
我有3个文件。
我的剧本:
---
- name: Create CPG
hosts: localhost
tasks:
- name: Create CPG "{{ cpg_name }}"
hpe3par_cpg:
storage_system_ip: "{{ storage_system_ip }}"
storage_system_username: "{{ storage_system_username }}"
storage_system_password: "{{ storage_system_password }}"
state: present
cpg_name: "{{ cpg_name }}"
#domain: "{{ domain }}"
growth_increment: "{{ growth_increment }}"
growth_increment_unit: "{{ growth_increment_unit }}"
growth_limit: "{{ growth_limit }}"
growth_limit_unit: "{{ growth_limit_unit }}"
growth_warning: "{{ growth_warning }}"
growth_warning_unit: "{{ growth_warning_unit }}"
raid_type: "{{ raid_type }}"
set_size: "{{ set_size }}"
high_availability: "{{ high_availability }}"
disk_type: "{{ disk_type }}"
我将在其中调用任务和变量的剧本:
---
- name: master
hosts: localhost
- import_playbook: create_CPG.yml
include_vars: properties/variables.yml
运行“ ansible-playbook create_master.yml”时出现此错误
ERROR! Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to have been in '/home/simon/Documents/Ansible/create_MasterPlaybook.yml': line 6, column 16, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- import_playbook: create_CPG.yml
include_vars: properties/variables.yml
^ here
是否有一种方法可以仅为此import_playbook调用带有变量的文件。
谢谢
答案 0 :(得分:2)
include_vars和import_playbook是任务。正确的语法如下。
- include_vars: properties/variables.yml
- import_playbook: create_CPG.yml
没有隔离variables。变量的范围是剧本。因此,要回答问题
是否有一种方法只能为此import_playbook调用带有变量的文件?
不。它不是。所包含的变量在整个剧本中都是可见的。
答案 1 :(得分:1)
import_playbook模块不接受-include_vars作为参数。
- import_playbook: create_CPG.yml
- include_vars: properties/variables.yml
要调用特定的include_vars,可以在该剧本中使用include_vars模块