您的位置:首页 > 其它

ansible之file模块

2016-05-02 21:20 225 查看
file用法选项
[root@ansible ~]# ansible-doc -s file
less 436
Copyright (C) 1984-2009 Mark Nudelman
less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less - name: Sets attributes of files
action: file
follow                 # This flag indicates that filesystem links, if they exist, should be followed.
force                  # force the creation of the symlinks in two cases: the source file does not exist (but will appear
later); the destination exists and is a file (so, we need to
unlink the "path" file and create symlink to the "src" file in
place of it).
group                  # name of the group that should own the file/directory, as would be fed to `chown'
mode                   # mode the file or directory should be. For those used to `/usr/bin/chmod' remember that modes are
actually octal numbers (like 0644). Leaving off the leading zero
will likely have unexpected results. As of version 1.8, the mode
may be specified as a symbolic mode (for example, `u+rwx' or
`u=rw,g=r,o=r').
owner                  # name of the user that should own the file/directory, as would be fed to `chown'
path=                  # path to the file being managed.  Aliases: `dest', `name'
recurse                # recursively set the specified file attributes (applies only to state=directory)
selevel                # level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the
`range'. `_default' feature works as for `seuser'.
serole                 # role part of SELinux file context, `_default' feature works as for `seuser'.
setype                 # type part of SELinux file context, `_default' feature works as for `seuser'.
seuser                 # user part of SELinux file context. Will default to system policy, if applicable. If set to
`_default', it will use the `user' portion of the policy if
available
src                    # path of the file to link to (applies only to `state=link'). Will accept absolute, relative and
nonexisting paths. Relative paths are not expanded.
state                  # If `directory', all immediate subdirectories will be created if they do not exist, since 1.7 they
will be created with the supplied permissions. If `file', the file
will NOT be created if it does not exist, see the [copy] or
[template] module if you want that behavior.  If `link', the
symbolic link will be created or changed. Use `hard' for
hardlinks. If `absent', directories will be recursively deleted,
and files or symlinks will be unlinked. If `touch' (new in 1.4),
an empty file will be created if the `path' does not exist, while
an existing file or directory will receive updated file access and
modification times (similar to the way `touch` works from the
command line).


模块选项
force:需要在两种情况下强制创建软链接,一种是源文件不存在但之后会建立的情况下;另一种是目标软链接已存在,需要先取消之前的软链,然后创建新的软链,有两个选项:yes|no group:定义文件/目录的属组 mode:定义文件/目录的权限 owner:定义文件/目录的属主 path:必选项,定义文件/目录的路径 recurse:递归的设置文件的属性,只对目录有效 src:要被链接的源文件的路径,只应用于state=link的情况 dest:被链接到的路径,只应用于state=link的情况 state: directory:如果目录不存在,创建目录 file:即使文件不存在,也不会被创建 link:创建软链接 hard:创建硬链接 touch:如果文件不存在,则会创建一个新的文件,如果文件或目录已存在,则更新其最后修改时间 absent:删除目录、文件或者取消链接文件

示例创建文件




查看创建的文件




吧创建的pk文件链接为xo





创建目录





吧pk文件删除





吧之前wc目录删除,和删除文件方式类似



删除xo链接




好了file模块就到此,更多的方式看用法以及官方即可。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  file 模块 ansible