我是ansible的新手,所以请原谅任何不正确的语法错误。我有一个简单的剧本,安装包
我的项目结构如下:
TopDir
dev
|roles
| |ant
| | |install
| | | tasks
| | | main.yml
| | |vars
| | main.yml
| |ant-junit
| |install
| | tasks
| | main.yml
| |vars
| main.yml
|install_tools.yml
行动手册(install_tools.yml(:
- name: Install tools
hosts: hostA
tags: ['hostA']
become: yes
roles:
- ant/install
- ant-junit/install
- doxygen/install
每个install/main.yml看起来都和这个一模一样
- name: Include variables in vars
include_vars: ../../vars/main.yml
- name: Install {{tool_name}}
yum:
name: "{{tool_name}}-{{tool_version}}"
state: present
在每个vars/main.yml中,我定义了tool_name和tool_version。因此,我想做如下操作,但vars_files不是TaskInclude的有效属性。其想法是generic_install将使用vars_files 中定义的变量
- name: Call generic install
include_tasks: ../../../generic_install.yml
vars_files: ../../vars/main.yml
我使用了错误的属性。以下对我有效。请注意,我必须使用import_task而不是include_tasks。我不太确定其中的区别,但它只适用于import_tasks和vars
- name: Call generic install
import_tasks: ../../../generic_install.yml
vars:
tool_name: "{{tool_name}}"
tool_version: "{{tool_version}}"