创建空文件,类似于touch #ansible dns -m file -a 'path=/app/dir2/abc.txt state=touch mode=0666 owner=ftp' 创建空目录, 类似于mkdir -p #ansible dns -m file -a 'path=/app/dir2/dir3/dir4 state=directory mode=0666 owner=ftp' ├ dir2 │└── dir3 │ └── dir4 创建软链接 #a...
touch:如果文件不存在,则会创建一个新的文件,如果文件或目录已存在,则更新其最后修改时间 absent:删除目录、文件或者取消链接文件 用法举例如下: ① 创建目录: [root@server ~]#ansible web -m file -a 'path=/data/app state=directory'192.168.37.122 | SUCCESS =>{"changed": true,"gid": 0,"group":"...
[root@Ansible ~]# ansible web -m file -a "path=/tmp/xz_test state=touch mode=0644" 192.168.8.66 | SUCCESS => { "changed": true, "dest": "/tmp/xz_test", "gid": 0, "group": "root", "mode": "0644", "owner": "root", "size": 0, "state": "file", "uid": 0 } [r...
"msg": "File exists." } TASK [create_delete_folder : Check that if the file devnet.md not exists] *** skipping: [127.0.0.1] STEP03: 我们创建一个 task 来使用创建这个文件 devnet.md - name: Create the file, if it doesnt exist already file: path: /etc/devnet.md state: touch when:...
file:即使文件不存在,也不会被创建 link:创建软链接 hard:创建硬链接 touch:如果文件不存在,则会创建一个新的文件,如果文件或目录已存在,则更新其最后修改时间 absent:删除目录、文件或者取消链接文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
file: 即使文件不存在,也不会被创建; link: 创建软链接; hard: 创建硬链接; touch: 如果文件不存在,则会创建一个新的文件,如果文件或目录已存在,则更新其最后修改时间; absent: 删除目录、文件或者取消链接文件; [root@ansible-server ~]# ansible web-nodes -m file -a "path=/data/test state=touch mo...
state=file 代表拷贝后是文件; state=link 代表最终是个软链接; state=directory 代表文件夹; state=hard 代表硬链接; state=touch 代表生成一个空文件; state=absent 代表删除 Managing Packages 安装软件包 假如软件包安装了,则不做任何操作;没安装,则安装: $ ansible webservers -m yum -a "name=httpd st...
skipped, since /data/1.txt exists #文件已存在就不在执行touch命令 实例1-3 removes [root@m01 ~]# ansible web01 -m shell -a "\rm -f /data/1.txt removes=/data/1.txt" web01 | CHANGED | rc=0 >> [root@m01 ~]# ansible web01 -m shell -a "\rm -f /data/1.txt removes=/data...
Iftouch(new in 1.4), an empty file will be created if the file does not exist, while an existing file or directory will receive updated file access and modification times (similar to the waytouchworks from the command line). Default is the current state of the file if it exists,directory...
Changed if file not exists. Create empty file. - name: create fake 'nologin' shell file: path: /etc/nologin state: touch register: p changed_when: p.diff.before.state == "absent" Share Follow answered May 20, 2019 at 12:31 Dmitry Balashov 1111 bronze badge Add a comment 1 ...