ansible文件操作模块<6>,ansible操作模块


前面我对ansible的fetch模块,copy,file,blockinfile,lineinfile进行了学习,这次再次跟随http://www.zsythink.net/archives/2560
学习ansible的其它模块

find模块

类似于我们的find命令,可以帮助我们找到受管主机中符合条件的文件或者字符
先来看一下参数:
image
ansible test177 -m find -a 'path=/root/ contains=".love."'
在我的177上的root目录下查找包含字符串‘love’的文件,不会递归查找,只会在此目录下找对应的文件
image
image
假如我要找的文件在二级目录或者三级目录下,那么我就需要用到下面这条命令:
ansible test177 -m find -a 'paths=/root/ contains=".love." recurse=yes'
在root的子目录下找关键词所对应的文件,但是不包含隐藏文件:
image
ansible test177 -m find -a 'paths=/root/ patterns="*.sh" file_type=any hidden=yes'
在root目录下找出所有以.sh结尾的文件,包括隐藏文件,文件类型不限,但不进行递归查找:
image
ansible test177 -m find -a 'path=/root/ age=-4d recurse=yes'
在root下找出四天内的文件,不包含隐藏文件,目录和软连接文件类型
image
ansible test177 -m find -a 'path=/root/ size=2k recurse=yes'
在177的root下找出大于2k的文件,不包含隐藏文件,目录或者软连接等文件类型

replace模块:

image
很明显。replace是作为ansible的一个替换功能的模块,会将你指定的字符替换成你想要的新字符
ansible test177 -m replace -a 'path=/root/file1 regexp="love" replace=loving'
将177的file1 文件中的‘love’字符替换成‘loving’
image
ansible test177 -m replace -a 'path=/root/file1 regexp="loving" replace=love backup=yes'
把177的file1中的loving替换成love,但是在替换之前进行源文件备份
image

相关内容