gpt4 book ai didi

linux - 运行 playbook 进行 apache 状态检查时抛出错误

转载 作者:太空宇宙 更新时间:2023-11-04 10:15:50 25 4
gpt4 key购买 nike

我写了下面的剧本来检查 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]$

最佳答案

您有一个 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"

关于linux - 运行 playbook 进行 apache 状态检查时抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46300764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com