Ansible's File module

Source: Internet
Author: User


File Usage Options

[[email protected] ~]# ansible-doc -s fileless 436copyright  (C)   1984-2009 mark nudelmanless 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,                &nbSp;               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).


Module options

Force : You need to force the creation of a soft link in both cases, one where the source file does not exist but will be established later, the other is that the target soft link already exists, need to first cancel the previous soft chain, and then create a new soft chain, there are two options: Yes|no

Group : Defines a group of files/directories

Mode : Define permissions for files/directories

owner : Defines the owner of a file/directory

path: required option, defines the path to the file/directory

recurse: Properties of the recursive settings file, valid only for the directory

src : The path to the source file to be linked to only the State=link case

dest : The path that is linked to, applies only to the case of State=link

State :

Directory : If the directory does not exist, create a directory

file : Even if the file does not exist, it will not be created

Link : Creating a soft link

Hard : Create a hard link

Touch : If the file does not exist, a new file is created and the last modified time is updated if the file or directory already exists

Absent : Deleting directories, files, or unlinked files


Example creating a file

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/7F/A6/wKiom1cnUMiQiC43AAFcVOa0_rg878.jpg "title=" 12.jpg "alt=" Wkiom1cnumiqic43aafcvoa0_rg878.jpg "/>

View the created file

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M02/7F/A4/wKioL1cnUd-S5T84AAJcnfiGUKU533.jpg "title=" 13.jpg "alt=" Wkiol1cnud-s5t84aajcnfiguku533.jpg "/>



Create the PK file link for XO

650) this.width=650; "src=" http://s4.51cto.com/wyfs02/M00/7F/A6/wKiom1cnUdrCEHmPAAPgNE7c1wo787.jpg "title=" 14.jpg "alt=" Wkiom1cnudrcehmpaapgne7c1wo787.jpg "/>


Create a Directory

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M01/7F/A4/wKioL1cnU0nAKbsNAAP5Bca7Uec019.jpg "title=" 15.jpg "alt=" Wkiol1cnu0nakbsnaap5bca7uec019.jpg "/>


Yes, PK file delete

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M02/7F/A6/wKiom1cnUwWDb708AANfdg_1c_k473.jpg "title=" 16.jpg "alt=" Wkiom1cnuwwdb708aanfdg_1c_k473.jpg "/>


Before the WC catalog was deleted, and deleted files in a similar way

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M02/7F/A4/wKioL1cnVEfTMwHZAAMfHgq_Bls675.jpg "title=" 17.jpg "alt=" Wkiol1cnveftmwhzaamfhgq_bls675.jpg "/>

Remove XO link

650) this.width=650; "src=" http://s1.51cto.com/wyfs02/M00/7F/A6/wKiom1cnU93xHP2IAAMF-dnCr8g231.jpg "title=" 18.jpg "alt=" Wkiom1cnu93xhp2iaamf-dncr8g231.jpg "/>



OK, the file module to this, more ways to look at the use and official can ...

This article is from the "Village Boys" blog, please make sure to keep this source http://noodle.blog.51cto.com/2925423/1769535

Ansible's File module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.