调用角色的 dir 参数 [英] the dir parameter for calling roles

查看:21
本文介绍了调用角色的 dir 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的剧本中有这一点.

 roles:
  - {role: cleanup-create, dir: '/standard/', commit: "{{choice}}"}

文件结构为/roles/standard/cleanup-create/tasks/main.yml

The file structure is /roles/standard/cleanup-create/tasks/main.yml

但我收到此错误:

ERROR! the role 'cleanup-create' was not found in /home/myuser/network-ansible-myuser/roles:/home/myuser/network-ansible-myuser:/etc/ansible/roles

The error appears to have been in '/home/myuser/network-ansible-myuser/configure-files.yml': line 15, column 5, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  roles:
  - {role: cleanup-create, dir: '/standard', commit: "{{choice}}"}
    ^ here

现在,错误消息似乎是说在/roles 中找不到我的角色.但是 dir 参数应该使它看起来在/roles/standard 下.

Now, the error message seems to be saying my role wasn't found in /roles. However the dir parameter should make it look under /roles/standard.

我发誓,它在 5 分钟前就开始工作了!

It was working 5 minutes ago, I swear!

推荐答案

您实际上可以设置 roles_path 配置变量(或者在命令行中传递它 - 试试看,我不确定你是否可以用 roles_path 做到这一点).

You can actually set roles_path configuration variable in ansible.cfg (or maybe pass it in the command line - try it, I'm not sure if you can do this with roles_path).

来自文档:

角色路径表示在 playbook 项目的 roles/ 子目录之外的其他目录,用于搜索以查找 Ansible 角色

The roles path indicate additional directories beyond the roles/ subdirectory of a playbook project to search to find Ansible roles

./roles 将首先从 playbook 目录中搜索,然后会检查其他路径.

./roles from playbook directory will be searched first, then additional paths will be checked.

您可以指定多个目录来查找角色

You can specify multiple directories to look for roles in

roles_path=/var/opt/my_roles:/var/opt/more_roles

这篇关于调用角色的 dir 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆