Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ansible从文件中删除最后三行_Ansible - Fatal编程技术网

使用ansible从文件中删除最后三行

使用ansible从文件中删除最后三行,ansible,Ansible,我想使用ansible删除文件的最后三行。我尝试使用lineinfle,但它删除了文件中的所有行。我已经把我的档案和剧本贴在下面了。我想使用ansible删除nfs\u配置、nfs\u共享和mount\u路径 file.txt [图片] [门票] [unix套接字] [nfs_配置] nfs\u共享= 山路= Ansible剧本 - name: Remove mount path from daemon.conf for clean-daemon linefile: path:

我想使用ansible删除文件的最后三行。我尝试使用lineinfle,但它删除了文件中的所有行。我已经把我的档案和剧本贴在下面了。我想使用ansible删除nfs\u配置、nfs\u共享和mount\u路径

file.txt

[图片]

[门票]

[unix套接字]

[nfs_配置]

nfs\u共享=

山路=

Ansible剧本

- name: Remove mount path from daemon.conf for clean-daemon

  linefile:

    path: /etc/ovirt-imageio-daemon/daemon.conf

    regexp: "[nfs_config]"

    state: absent
 
regexp:“[nfs\u config]”
没有执行您想要的操作,您需要使用“[nfs\u config]”,否则您将匹配
[]
之间的任何字符。这就是它删除多行的原因

另外,只需使用3个
lineinfile
命令来匹配
nfs\u config
nfs\u share
mount\u path

您可以将onee
LineInFile
与一个复杂的正则表达式一起使用来匹配它们,但是使用3个清晰的正则表达式将更易于阅读/维护。

使用。下面的任务将从配置文件中删除
nfs\u config
部分

-ini\u文件:
路径:/etc/ovirt imageio daemon/daemon.conf
节:nfs\u配置
国家:缺席