这是我的playbook.yaml
pre_tasks:
- name: Install required ansible-galaxy roles
local_action: shell ansible-galaxy install -r requirements.yaml
roles:
- role: gantsign.golang
vars:
golang_version: "1.16.3"
golang_install_dir: "/opt/go/{{ golang_version }}"还有我的requirements.yaml
---
- src: gantsign.golang但是,pre_task似乎从来没有被执行过,因此没有找到角色,并且配置失败。
知道为什么吗?
ERROR! the role 'gantsign.golang' was not found in /home/pkaramol/ansible
The error appears to be in '/home/pkaramol/ansible/airflow-playbook.yaml': line 33, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
roles:
- role: gantsign.golang
^ here看起来,ansible似乎是在尝试在开始游戏之前找到角色。由于某些原因,我很确定我以前做过这个过程(例如,让一个pre_task和local_action接管角色安装,但我现在似乎无法让它工作……)
编辑:我已经确认情况是这样的,因为当只将pre_task留给本地角色安装时,它实际上正在运行。
发布于 2021-04-22 19:54:10
正如您在该文档中所读到的:https://docs.ansible.com/ansible/latest/user_guide/playbooks_reuse_roles.html#using-roles-at-the-play-level
在播放级别使用角色选项时,Ansible将角色视为静态导入,并在剧本解析过程中处理它们。按这个顺序执行你的剧本..。
因此,角色本身需要在剧本开始运行之前找到并加载。
因此,如果您想在pre_tasks上使用银河,请尝试动态地将您的角色包含在游戏的任务部分:https://docs.ansible.com/ansible/latest/collections/ansible/builtin/include_role_module.html#include-role-module。
pre_tasks:
- name: Install required ansible-galaxy roles
local_action: shell ansible-galaxy install -r requirements.yaml
tasks:
- name: include my roles
include_role:
name: gantsign.golang
https://stackoverflow.com/questions/67210821
复制相似问题