仅检查文件中是否存在一行(可翻译) [英] Only check whether a line present in a file (ansible)
本文介绍了仅检查文件中是否存在一行(可翻译)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Ansible中,我需要检查文件中是否存在特定行.基本上,我需要将以下命令转换为可完成的任务.我的目标是只检查.
In ansible, I need to check whether a particular line present in a file or not. Basically, I need to convert the following command to an ansible task. My goal is to only check.
grep -Fxq "127.0.0.1" /tmp/my.conf
推荐答案
- name: Check whether /tmp/my.conf contains "127.0.0.1"
command: grep -Fxq "127.0.0.1" /tmp/my.conf
register: checkmyconf
check_mode: no
ignore_errors: yes
changed_when: no
- name: Greet the world if /tmp/my.conf contains "127.0.0.1"
debug: msg="Hello, world!"
when: checkmyconf.rc == 0
更新2017-08-28::较旧的Ansible版本需要使用always_run: yes
而不是check_mode: no
.
Update 2017-08-28: Older Ansible versions need to use always_run: yes
instead of check_mode: no
.
这篇关于仅检查文件中是否存在一行(可翻译)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文