Ansible 易读集合用法

Ansible 易读集合用法,ansible,Ansible,我试图使用Ansible集合作为例子 目录树结构如下所示: ├── ansible_collections │   └── nginxinc │   └── nginx_core │   ├── CHANGELOG.md ....... │   ├── README.md │   └── roles │   ├── nginx │  

我试图使用Ansible集合作为例子

目录树结构如下所示:

    ├── ansible_collections
    │   └── nginxinc
    │       └── nginx_core
    │           ├── CHANGELOG.md
.......
    │           ├── README.md
    │           └── roles
    │               ├── nginx
    │               │   ├── tasks
    │               │   │   ├── amplify
    │               │   │   ├── config
    │               │   │   ├── keys
    │               │   │   ├── main.yml
    │               │   │   ├── modules
    │               │   │   ├── opensource
    │               │   │   │   └── install-debian.yml
    │               │   │   └── unit
    ....
        ├── hosts
        └── site.yaml
我编写的
site.yaml
文件是:

- name: Demo
  hosts: all
  connection: local
  gather_facts: no

  tasks:
  - name: test
    include_role:
      name: nginxinc.nginx_core.nginx
      tasks_from: install-debian
我正在尝试从nginx角色运行任务
安装debian

我运行剧本:

ansible-playbook -i hosts my_nginx_playbook.yaml
ansible playbook-i托管站点.yaml

我得到这个错误:

错误!找不到角色“nginxinc.nginx_core.nginx…”。


我需要有关如何修复
site.yaml
文件的帮助如果我理解正确,您只需使用以下命令安装Nginx集合即可:

它应该安装在
~/.ansible/collections/ansible\u collections/nginxinc/nginx\u core/
中。然后创建一个剧本,如下所示:

最后运行您的剧本:

ansible-playbook -i hosts my_nginx_playbook.yaml

如果您的主机是Debian,它将为您选择Debian版本。

我很抱歉,这对我不起作用。这给人的印象是没有使用集合路径

ansible——版本 表2.9.17

ansible配置视图 集合安装在/usr/local/ansible_collections文件夹中:

树-L2/usr/local/ansible_collections/nginxinc/ 以下是剧本的基本内容:

ansible-playbook -i hosts my_nginx_playbook.yaml
cat剧本/nginx_core.yml 启动时,我们会收到以下错误消息:

ansible playbook playbooks/nginx_core.yml——额外变量target=myvm.mydomain.org 它在集合中找不到角色,更糟糕的是,它没有说它在集合路径中查找

但这里有一个解决方案是可行的,但它非常丑陋:在roles\u路径中添加集合的nginx角色

roles_path=/usr/local/galaxy-roles:./roles:/usr/local/ansible_collections/nginxinc/nginx_core/roles
警告:这显然是对ansible集合的滥用

任何帮助都将不胜感激


Ernest.

nginxinc.nginx\u core.nginx
不是角色,而是集合。你想做什么,因为NGINX的集合可以做很多事情,比如安装NGINX、配置NGINX……我试图理解如何正确调用属于集合的角色中的任务。我正在将我的项目从角色转移到集合。我已经在问题@β.εηοιτ.βε中阐明了我试图实现的目标
/usr/local/ansible_collections/nginxinc/
└── nginx_core
    ├── CHANGELOG.md
    ├── CODE_OF_CONDUCT.md
    ├── CONTRIBUTING.md
    ├── docs
    ├── FILES.json
    ├── LICENSE
    ├── MANIFEST.json
    ├── playbooks
    ├── plugins
    ├── README.md
    └── roles
- name: Test collection ansible with nginxinc
 hosts: "{{ target }}"
  collections:
    - nginxinc.nginx_core
  tasks:
    - import_role:
        name: nginx
ERROR! the role 'nginx' was not found in nginxinc.nginx_core:ansible.legacy:/usr/local/ansible-admin/playbooks/roles:/usr/local/galaxy-roles:/usr/local/ansible-admin/roles:/usr/local/ansible-admin/playbooks
roles_path=/usr/local/galaxy-roles:./roles:/usr/local/ansible_collections/nginxinc/nginx_core/roles