任务的 Ansible 剧本语法错误:
Ansible playbook syntax error with tasks:
我刚开始尝试使用 ansible,我正在尝试编写我的第一本简单的剧本。
但是我遇到了任务键的语法错误,
---
name: add ansible user
hosts: all
become: true
become_method: sudo
become_user:root
tasks:
- user:
name: ansible
groups: ansible
当我 运行 得到以下结果时:
utility:~/scripts/ansible# ansible-playbook --check add-ansible-user.yml
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/root/scripts/ansible/add-ansible-user.yml': line 8, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
^ here
通过搜索我认为最好的选择是我有一个缩进问题,但无论我如何尝试改变它,我都无法解决它。
- name: add ansible user
hosts: all
become: true
become_method: sudo
become_user: root
tasks:
- user:
name: ansible
groups: ansible
确实是缩进问题。请尝试上面写的代码。
问题出在这里:
become_user:root
您需要 :
和 root
之间的 space
become_user: root
我刚开始尝试使用 ansible,我正在尝试编写我的第一本简单的剧本。 但是我遇到了任务键的语法错误,
---
name: add ansible user
hosts: all
become: true
become_method: sudo
become_user:root
tasks:
- user:
name: ansible
groups: ansible
当我 运行 得到以下结果时:
utility:~/scripts/ansible# ansible-playbook --check add-ansible-user.yml
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/root/scripts/ansible/add-ansible-user.yml': line 8, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
tasks:
^ here
通过搜索我认为最好的选择是我有一个缩进问题,但无论我如何尝试改变它,我都无法解决它。
- name: add ansible user
hosts: all
become: true
become_method: sudo
become_user: root
tasks:
- user:
name: ansible
groups: ansible
确实是缩进问题。请尝试上面写的代码。
问题出在这里:
become_user:root
您需要 :
和 root
become_user: root