【问题标题】:Automatic Ansible custom modules installation with Ansible Galaxy使用 Ansible Galaxy 自动安装 Ansible 自定义模块
【发布时间】:2020-02-20 23:11:52
【问题描述】:

有没有什么好的方法可以使用 Ansible Galaxy 命令来安装和启用 Ansible (2.7.9) 自定义模块?

我的要求允许 Ansible Galaxy 下载嵌入我的自定义模块的正确 Ansible 角色。一旦ansible-galaxy install --roles-path ansible/roles/ -r roles/requirements.yml,我得到以下结构(非详尽):

├── ansible
│   ├── roles
│   │   ├── mymodule (being imported by Galaxy)
│   │   │   ├── library
│   │   │   │   └── mymodule.py

通过查看这部分文档,我的模块似乎在正确的位置,不需要任何进一步的配置:https://docs.ansible.com/ansible/latest/user_guide/playbooks_best_practices.html?highlight=library#directory-layout

但是当我找到这部分文档时,我感到很困惑。 ANSIBLE_LIBRARY 是否与自定义模块相关?

DEFAULT_MODULE_PATH

描述:Ansible 将在其中搜索模块的冒号分隔路径。

类型:路径规范

默认:~/.ansible/plugins/modules:/usr/share/ansible/plugins/modules

Ini 部分:默认值

Ini 键:库

环境:ANSIBLE_LIBRARY

https://docs.ansible.com/ansible/latest/reference_appendices/config.html#default-module-path

调用我的模块时,

  - name: Test of my Module
    mymodule:

我收到以下错误:

ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

我希望不必配置ANSIBLE_LIBRARY 和自动调用模块。我理解正确还是应该欺骗这个变量?

【问题讨论】:

    标签: ansible ansible-galaxy


    【解决方案1】:

    如果你的自定义模块是一个角色,你需要在你的剧本中包含这个角色,所以至少:

    ---
    - hosts: myhosts
    
      roles:
        - role: mymodule
    
      tasks:
        - name: Test of my Module
          mymodule:
    

    【讨论】:

    • 像魅力一样工作!不确定为什么我们需要明确包含它。有任何解释或文件吗?
    • 默认情况下,Ansible 在启动您的剧本时不会解析您的所有角色。角色可以包含例如处理程序。只有在使用角色时才能使用这些处理程序。自定义模块也是如此。您可以将模块放在与您的剧本相同级别的 library 文件夹中。这些将被无条件解析。
    猜你喜欢
    • 1970-01-01
    • 2014-10-03
    • 1970-01-01
    • 2021-06-27
    • 2022-11-07
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    • 2023-02-02
    相关资源
    最近更新 更多