ansible-file模块使用方法

应用

管理远程主机文件,创建文件或目录,删除文件或目录,修改文件或目录的权限等

参数

  • path:
  • state=directory|touch|link|hard|absent:依次对应 目录|文件|软链接|硬链接|删除
  • src:前提state=link|hard时,需要指定链接源
  • force:state=link,force=yes表示强制创建链接文件,若有同名则覆盖
  • owner:指定属主
  • group:指定属组
  • mode:指定权限mode=655,mode=0700
  • recurse:当操作的对象是目录时,recurse=yes,可以递归修改目录中文件的属性

示例

  1. 在/opt目录下创建test目录,并在/opt/test目录下创建test01文件,属主属组为test,权限644
]# ansible all -m file -a 'path=/opt/test state=directory'
]# ansible all -m file -a 'path=/opt/test/test01 state=touch'
]# ansible all -m file -a 'path=/opt/test/test01 owner=test group=test mode=644'
  1. 为/opt/test/test01文件创建软链接,软链接名ltest01
]# ansible all -m file -a 'path=/opt/test/ltest01 state=link src=/opt/test/test01'

猜你喜欢

转载自www.cnblogs.com/wanwz/p/12923174.html