我写了下面的剧本来检查运行apache的状态:
#Demo for testing ansible playbook.
- hosts: lab
become_user: root
serial: 1
tasks:
#purpose of this task is to check apache running status
-name: verify apache running status
shell: if ps -eaf | egrep 'apache|http'|grep -v grep > /dev/null ; then echo 'process_running'; else echo 'process_not_running';fi
ignore_errors: true
register: appprocesscheck
# this task is decision,play will fail/quit,if application is running
-name: decision point to start patching
fail: msg="{{ inventory_hostname }} have running Application.Please stop the application first, then attempt patching."
when: appprocesscheck.stdout == "process_running"
我收到以下错误。请帮我解决这个问题。
[ansibleUser@blb44cehanstst ansible]$ ansible-playbook testweb.yml
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/etc/ansible/testweb.yml': line 13, column 15, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
-name: verify apache running status
shell: if ps -eaf | egrep 'apache|http'|grep -v grep > /dev/null ; then echo 'process_running'; else echo 'process_not_running';fi
^ here
[ansibleUser@blb44cehanstst ansible]$
答案 0 :(得分:1)
您有YAML语法错误。
在两个任务中-
和name
之间留一个空格。
- name: verify apache running status
shell: if ps -eaf | egrep 'apache|http'|grep -v grep > /dev/null ; then echo 'process_running'; else echo 'process_not_running';fi
ignore_errors: true
register: appprocesscheck
- name: decision point to start patching
fail: msg="{{ inventory_hostname }} have running Application.Please stop the application first, then attempt patching."
when: appprocesscheck.stdout == "process_running"