【问题标题】:Install ansible galaxy using ansible使用 ansible 安装 ansible Galaxy
【发布时间】:2019-06-18 15:30:44
【问题描述】:

如何使用 ansible 安装 ansible 角色?

手动方式是使用命令行:

ansible-galaxy install user.role

但是我如何在 ansible 本身中做到这一点,就像一个模块?我会在剧本中猜到这样的事情:

- tasks:
  galaxy:
    user: username
    role: rolename
    state: installed

这似乎是一项非常琐碎和初级的任务,但我找不到如何去做。

这里有一个类似的问题How to automatically install Ansible Galaxy roles?。但它没有回答它,因为它每次只是运行手动命令,而且它不是幂等的(这是使用 ansible 自动化处理的主要原因)。

【问题讨论】:

    标签: ansible ansible-galaxy


    【解决方案1】:

    你的结论“it just runs the manual command every time, and it is not idempotent”太快了。这样的任务在参数creates 和适当的ansible_roles_list 下是幂等的。

    - name: Install roles from Ansible Galaxy
      command: "ansible-galaxy install {{ item.role_name }}"
      args:
        creates: "{{ item.role_path }}"
      loop: "{{ ansible_roles_list }}"
    

    【讨论】:

      【解决方案2】:

      这个问题对新手来说不是那么明显并且在介绍性文档中不容易找到的要点是galaxy 的角色只需要安装在客户端,而不是服务器上

      因此,在服务器的剧本中,您不必每次设置服务器时都安装 galay 角色,而只需在客户端计算机中安装一次。

      【讨论】:

      • Ansible 非常灵活。这些角色也经常安装在服务器上。例如让 playbook 使用 ansible-pull 运行。
      猜你喜欢
      • 2020-02-20
      • 2016-10-25
      • 2023-02-02
      • 2016-08-25
      • 2021-03-10
      • 2014-10-03
      • 1970-01-01
      • 2020-08-15
      • 2014-03-02
      相关资源
      最近更新 更多