问题描述
在 Ansible Tower 中工作时,我试图通过复制名为“files”的 github 存储库子文件夹中的新版本来更新服务器上的 codedeployagent.yml 文件。但是,当我在 Ansible Tower 中运行模板时,出现以下错误(如下):
ERROR! Syntax Error while loading YAML.
mapping values are not allowed in this context
The error appears to be in '/tmp/awx/project/files/codedeployagent.yml': line 2,column 14,but may be elsewhere in the file depending on the exact Syntax problem.
The offending line appears to be:
--
:log_aws_wire: false
^ here
这就像 Ansible Tower 将 codedeployagent.yml 文件视为 ansible 文件,当我不希望它这样做时,我只想复制该文件。 可能是因为配置文件是 .yml 格式,我需要在源代码库中更改它吗?这是我的 ansible playbook(如下)。任何建议表示赞赏,谢谢。
---
-
become: yes
hosts: all
remote_user: admin
tasks:
- block:
- name: remove original CodeDeploy Agent config
file:
path: /etc/codedeploy-agent/conf/codedeployagent.yml
state: absent
- name: copy latest CodeDeploy Agent file
template:
dest: /etc/codedeploy-agent/conf/codedeployagent.yml
mode: 420
src: files/codedeployagent.yml
tags:
- config
- name: restart CodeDeploy Agent
service: name=codedeploy-agent state=restarted
vars_files:
- files/codedeployagent.yml
解决方法
只是想感谢@Zeitounator 引导我朝着正确的方向前进,下面的 ansible playbook 现在运行良好
---
-
become: yes
hosts: all
remote_user: admin
tasks:
- block:
- name: remove original CodeDeploy Agent config
file:
path: /etc/codedeploy-agent/conf/codedeployagent.yml
state: absent
- name: copy latest CodeDeploy Agent file
template:
dest: /etc/codedeploy-agent/conf/codedeployagent.yml
mode: 420
src: files/codedeployagent.yml
tags:
- config
- name: restart CodeDeploy Agent
service: name=codedeploy-agent state=restarted