Ansible在一个剧本中混合角色和apt
我刚开始学习Ansible,在同一本书中找不到任何讨论使用角色和apt的文档。我写的剧本在这里Ansible在一个剧本中混合角色和apt,ansible,Ansible,我刚开始学习Ansible,在同一本书中找不到任何讨论使用角色和apt的文档。我写的剧本在这里 --- - hosts: apps become: yes tasks: - name: Install distutils apt: name: python3-distutils state: present - name: Run roles roles: - geerlingguy.git
---
- hosts: apps
become: yes
tasks:
- name: Install distutils
apt:
name: python3-distutils
state: present
- name: Run roles
roles:
- geerlingguy.git
- mdklatt.python3
- geerlingguy.nodejs
但这给了我一个错误
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to be in '/home/simon/ansible/playbooks/base_apps_server.yml': line 9, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
state: present
- name: Run roles
^ here
roles指令不是模块,不能在任务中使用。看
或者将角色置于任务之前
- hosts: apps
become: yes
roles:
- geerlingguy.git
- mdklatt.python3
- geerlingguy.nodejs
tasks:
- name: Install distutils
apt:
name: python3-distutils
state: present
,或使用
您可以使用pre_任务来完成此任务:
剧本中定义的任何预演任务。
由pre_任务触发的任何处理程序。
角色中列出的每个角色,按列出的顺序排列。在角色的meta/main.yml中定义的任何角色依赖项都将首先运行,并受标记筛选和条件约束。有关更多详细信息,请参阅使用角色依赖项。
剧本中定义的任何任务。
由角色或任务触发的任何处理程序。
剧本中定义的任何后期任务。
由post_任务触发的任何处理程序。
角色不属于任务。对于任务中的角色,请使用import_role:我最近发现了第二个角色,我必须承认我更喜欢它而不是角色,主要是因为它感觉对剧本中发生的事情有更细粒度的控制。你有什么偏好和理由吗?从技术上讲,没有区别。include_角色更灵活,同时也更复杂。例如,整个剧本都可以使用。应该正确理解所包含角色的详细信息。包括复杂的下载角色可能会带来惊喜。另一方面,适当分散的角色使生活更轻松。这是一种权衡。
- hosts: apps
become: yes
tasks:
- name: Install distutils
apt:
name: python3-distutils
state: present
- name: Run role
include_role:
name: geerlingguy.git
- name: Run role
include_role:
name: mdklatt.python3
- name: Run role
include_role:
name: geerlingguy.nodejs
- hosts: apps
become: yes
pre_tasks:
- name: Install distutils
apt:
name: python3-distutils
state: present
roles:
- geerlingguy.git
- mdklatt.python3
- geerlingguy.nodejs