我想在主要任务中有2个"子任务",但由于某种原因我得到语法错误.
在我的/etc/ansible目录中,我必须遵循以下结构:
playbooks/
set_users.yml
roles/
users/
tasks/
main.yml
create_admin.yml
update_root.yml
vars/
main.yml
Run Code Online (Sandbox Code Playgroud)
在create_admin.yml文件中我有以下内容:
---
- name: Create srv_admin user
user: name=srv_admin password="{{ admin_password }}" groups=wheel shell=/bin/bash
Run Code Online (Sandbox Code Playgroud)
并在update_root.yml:
---
- name Update root password
user: name=root password="{{ root_password }}"
Run Code Online (Sandbox Code Playgroud)
然后我将这些任务包含在main.yml:
---
- name: Modify users
tasks:
- include: update_root.yml
- include: create_admin.yml
Run Code Online (Sandbox Code Playgroud)
我vars/main.yml包含了我的密码:
---
admin_password: SHA512HASH
root_password: SHA512HAS
Run Code Online (Sandbox Code Playgroud)
现在将它们整合在一起playbooks/set_users.yml:
---
- name: create user
hosts: servers
remote_user: root
roles:
- users
Run Code Online (Sandbox Code Playgroud)
但我显然做错了什么.当我运行剧本时,我收到以下错误:
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/etc/ansible/roles/users/tasks/main.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: Modify users
^ here
Run Code Online (Sandbox Code Playgroud)
我如何使用这两个"子"任务,tasks/main.yml以便我可以简单地导入剧本中的角色?
编辑实施@Konstantin Suvorov建议后:
The error appears to have been in '/etc/ansible/roles/users/tasks/update_root.yml': line 3, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name Update root password
user: name=root password="{{ root_password }}"
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
Run Code Online (Sandbox Code Playgroud)
tasks/main.yml应该是一个任务列表,所以不需要tasks:关键字:
---
- include: update_root.yml
- include: create_admin.yml
Run Code Online (Sandbox Code Playgroud)
并且避免使用key=value语法,它会在腿部射击,使用纯YAML:
- name: Update root password
user:
name: root
password: "{{ root_password }}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5956 次 |
| 最近记录: |