gpt4 book ai didi

ansible - 在运行角色之前动态运行 "ansible-galaxy install -r requirement.yml -p roles/"作为先决条件

转载 作者:行者123 更新时间:2023-12-04 03:13:54 24 4
gpt4 key购买 nike

我正在尝试让以下 Ansible 剧本发挥作用,但无法弄清楚如何告诉 Ansible:

  • 忽略角色是否存在的检查
  • 运行 ansible-galaxy 命令以在使用前自动加载角色

这是我的代码:

- name: Install prerequisite roles
hosts: all
become: no

tasks:
- name: run ansible galaxy
local_action: command ansible-galaxy install -r requirements.yml -p roles/

- name: Install Oracle Java
hosts: tomcat-servers:ss-servers:ns-servers:ld-servers
become: yes

roles:
- raltd-jdk

我也尝试使用 pre_tasks 执行上述操作,但也没有用。我的 requirements.yml 就是这样的:

- src: git@gitserver.mydom.com:ansible/raltd-jdk.git
scm: git

我收到这个错误:

$ ansible-playbook -i inv/myinventory raltd-jdk.yml
ERROR! the role 'raltd-jdk' was not found in /path/to/ansible/roles:/etc/ansible/roles:/path/to/ansible

The error appears to have been in '/path/to/ansible/raltd-jdk.yml': line 16, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

roles:
- raltd-jdk
^ here

引用资料

最佳答案

我也在使用 requirements.yml,然后使用 include_role立即运行它们。

include* 语句是 processed as they are encountered .

- name: Get required roles with ansible galaxy
local_action: command ansible-galaxy install -r requirements.yml -p roles/

- name: Install some.role
include_role:
name: some.role

关于ansible - 在运行角色之前动态运行 "ansible-galaxy install -r requirement.yml -p roles/"作为先决条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42726089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com