Molecule - 从其他目录测试角色

BEl*_*luu 9 ansible molecule

我想测试我在其他目录中的角色。\n在我的项目结构下方:\n项目结构

\n\n

当我尝试使用分子时,它找不到角色目录中的角色。

\n\n
\xe2\x9d\xaf sudo molecule converge\n--> Test matrix\n\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 default\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 dependency\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 create\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 prepare\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 converge\n\n--> Scenario: \'default\'\n--> Action: \'dependency\'\nSkipping, missing the requirements file.\nSkipping, missing the requirements file.\n--> Scenario: \'default\'\n--> Action: \'create\'\nSkipping, instances already created.\n--> Scenario: \'default\'\n--> Action: \'prepare\'\nSkipping, prepare playbook not configured.\n--> Scenario: \'default\'\n--> Action: \'converge\'\n--> Sanity checks: \'docker\'\nERROR! the role \'curl\' was not found in /home/belluu/programming/Ansible-Posthog/molecule/default/roles:/root/.cache/molecule/Ansible-Posthog/default/roles:/home/belluu/programming:/root/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles:/home/belluu/programming/Ansible-Posthog/molecule/default\n\nThe error appears to be in \'/home/belluu/programming/Ansible-Posthog/molecule/default/converge.yml\': line 5, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  roles:\n    - role: curl\n      ^ here\n
Run Code Online (Sandbox Code Playgroud)\n\n

分子试图找到正确的目录,但没有成功。\n是否可以为他提供带有角色的目录路径?

\n

小智 7

简单回答:是的

在您的 molecular.yml 文件中添加以下行env:

provisioner:
  name: ansible
  ...
  env:
    ANSIBLE_ROLES_PATH: "../../roles"
Run Code Online (Sandbox Code Playgroud)

此外,您还可以将 Molecule 链接到其他“路径”:

provisioner:
  name: ansible
  ...
  env:
    ANSIBLE_CONFIG: ../../ansible.cfg
  inventory:
    links:
      group_vars: ../../inventory/group_vars
      host_vars: ../../inventory/host_vars
Run Code Online (Sandbox Code Playgroud)