为多个 import_playbooks 包含一个文件中的变量 [英] Include vars from a file for multiple import_playbooks
问题描述
这是使用 Ansible 2.7 的错误
This is an error using Ansible 2.7
我正在尝试将一个包含变量的文件包含到我的具有多个 import_playbooks 的 playbook 中.
I am trying to include a files with vars in it into my playbook that has multiple import_playbooks.
我有 3 个文件.
- 一个包含所有变量
- 一个有剧本和任务的人
- 一个带有 import_playbook 的
我的剧本:
---
- 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 }}"
我将在其中调用我的任务和变量的剧本:
The playbook where I will call my tasks and my variables:
---
- name: master
hosts: localhost
- import_playbook: create_CPG.yml
include_vars: properties/variables.yml
运行ansible-playbook create_master.yml"时出现此错误
I get this error when running "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 调用带有变量的文件.
Is there a way to call a file with variables for only this import_playbook.
谢谢
推荐答案
问:"有没有办法只为这个 import_playbook 调用带有变量的文件?"em>
Q: "Is there a way to call a file with variables for only this import_playbook?"
A:不,不是.包含的变量在整个剧本中都是可见的.
A: No. It is not. The included variables are visible in the whole playbook.
include_vars 是一项任务.正确的语法如下
include_vars is a task. The correct syntax is below
- name: master
hosts: localhost
tasks:
- include_vars: properties/variables.yml
- import_playbook: create_CPG.yml
import_playbook不是任务.它是一个包含一个带有要执行的播放列表的文件"的模块.变量一本剧本.变量的范围是剧本.因此,回答这个问题
import_playbook is not a tasks. It is a module that "Includes a file with a list of plays to be executed". There is no isolation of variables among the plays in a playbook. The scope of the variables is the playbook. Hence, to answer the question
这篇关于为多个 import_playbooks 包含一个文件中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!