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

问题描述

我在剧本中有这方面的内容.

I've got this bit in my playbook.

 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 ansible.cfg中的="nofollow noreferrer">配置变量(或在命令行中传递-试试看,我不确定是否可以通过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 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参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 13:32