我只是从Ansible开始,在同一本书中找不到任何讨论使用角色和apt的文档。我写的剧本在这里
---
- 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
答案 0 :(得分:1)
roles 指令不是模块,不能在任务内使用。参见Using Roles。
将角色放在任务之前
- hosts: apps
become: yes
roles:
- geerlingguy.git
- mdklatt.python3
- geerlingguy.nodejs
tasks:
- name: Install distutils
apt:
name: python3-distutils
state: present
,或使用include_role
- 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
答案 1 :(得分:0)
您可以使用pre_tasks
完成此操作(see the execution order):
- 剧本中定义的任何
pre_tasks
。- 由pre_tasks触发的任何处理程序。
roles:
中列出的每个角色,按列出的顺序。角色的meta / main.yml中定义的所有角色依赖项都将首先运行,但要遵循标签过滤和条件。有关更多详细信息,请参见使用角色依赖性。- 剧本中定义的任何
tasks
。- 由角色或任务触发的任何处理程序。
- 剧本中定义的任何
post_tasks
。- 由post_tasks触发的任何处理程序。
- hosts: apps
become: yes
pre_tasks:
- name: Install distutils
apt:
name: python3-distutils
state: present
roles:
- geerlingguy.git
- mdklatt.python3
- geerlingguy.nodejs