Ansible
2.模块的使用
authorized_key模块添加sshkey认证
YUM模块的使用
COPY模块的使用
file
cron
firewalld
pam_limits
mysql_db
mysql_user
selinux
sysctl
yum
3.playbooks
初始化新安装CentOS7
模块文档工具ansible-doc
shell+register+when+模块RETURN变量
本文档使用 MrDoc 发布
-
+
首页
COPY模块的使用
# COPY模块的使用 ## TIPs 1. src和dest的目录名相同时,要以/结尾才能够实现覆盖拷贝,否则会在$dest下新建$src目录 ## 拷贝文件并修改文件归属用户及用户组 ``` ansible 2021php --become --become-method sudo --become-user root -m copy -a "src=/usr/local/php/etc/php-fpm.conf dest=/usr/local/php/etc/php-fpm.conf owner=www group=www" ``` ## 帮助文档 ``` > COPY (/usr/lib/python2.7/site-packages/ansible/modules/files/copy.py) The `copy' module copies a file from the local or remote machine to a location on the remote machine. Use the [fetch] module to copy files from remote locations to the local box. If you need variable interpolation in copied files, use the [template] module. Using a variable in the `content' field will result in unpredictable output. For Windows targets, use the [win_copy] module instead. * This module is maintained by The Ansible Core Team * note: This module has a corresponding action plugin. OPTIONS (= is mandatory): - attributes The attributes the resulting file or directory should have. To get supported flags look at the man page for `chattr' on the target system. This string should contain the attributes in the same order as the one displayed by `lsattr'. The `=' operator is assumed as default, otherwise `+' or `-' operators need to be included in the string. (Aliases: attr)[Default: (null)] type: str version_added: 2.3 - backup Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly. [Default: False] type: bool version_added: 0.7 - checksum SHA1 checksum of the file being transferred. Used to validate that the copy of the file was successful. If this is not provided, ansible will use the local calculated checksum of the src file. [Default: (null)] type: str version_added: 2.5 - content When used instead of `src', sets the contents of a file directly to the specified value. Works only when `dest' is a file. Creates the file if it does not exist. For advanced formatting or if `content' contains a variable, use the [template] module. [Default: (null)] type: str version_added: 1.1 - decrypt This option controls the autodecryption of source files using vault. [Default: True] type: bool version_added: 2.4 = dest Remote absolute path where the file should be copied to. If `src' is a directory, this must be a directory too. If `dest' is a non-existent path and if either `dest' ends with "/" or `src' is a directory, `dest' is created. If `dest' is a relative path, the starting directory is determined by the remote host. If `src' and `dest' are files, the parent directory of `dest' is not created and the task fails if it does not already exist. type: path - directory_mode When doing a recursive copy set the mode for the directories. If this is not set we will use the system defaults. The mode is only set on directories which are newly created, and will not affect those that already existed. [Default: (null)] type: raw version_added: 1.5 - follow This flag indicates that filesystem links in the destination, if they exist, should be followed. [Default: False] type: bool version_added: 1.8 - force Influence whether the remote file must always be replaced. If `yes', the remote file will be replaced when contents are different than the source. If `no', the file will only be transferred if the destination does not exist. Alias `thirsty' has been deprecated and will be removed in 2.13. (Aliases: thirsty)[Default: True] type: bool version_added: 1.1 - group Name of the group that should own the file/directory, as would be fed to `chown'. [Default: (null)] type: str - local_follow This flag indicates that filesystem links in the source tree, if they exist, should be followed. [Default: True] type: bool version_added: 2.4 - mode The permissions of the destination file or directory. For those used to `/usr/bin/chmod' remember that modes are actually octal numbers. You must either add a leading zero so that Ansible's YAML parser knows it is an octal number (like `0644' or `01777')or quote it (like `'644'' or `'1777'') so Ansible receives a string and can do its own conversion from string into number. Giving Ansible a number without following one of these rules will end up with a decimal number which will have unexpected results. As of Ansible 1.8, the mode may be specified as a symbolic mode (for example, `u+rwx' or `u=rw,g=r,o=r'). As of Ansible 2.3, the mode may also be the special string `preserve'. `preserve' means that the file will be given the same permissions as the source file. [Default: (null)] type: path - owner Name of the user that should own the file/directory, as would be fed to `chown'. [Default: (null)] type: str - remote_src Influence whether `src' needs to be transferred or already is present remotely. If `no', it will search for `src' at originating/master machine. If `yes' it will go to the remote/target machine for the `src'. `remote_src' supports recursive copying as of version 2.8. `remote_src' only works with `mode=preserve' as of version 2.6. [Default: False] type: bool version_added: 2.0 - selevel The level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the `range'. When set to `_default', it will use the `level' portion of the policy if available. [Default: s0] type: str - serole The role part of the SELinux file context. When set to `_default', it will use the `role' portion of the policy if available. [Default: (null)] type: str - setype The type part of the SELinux file context. When set to `_default', it will use the `type' portion of the policy if available. [Default: (null)] type: str - seuser The user part of the SELinux file context. By default it uses the `system' policy, where applicable. When set to `_default', it will use the `user' portion of the policy if available. [Default: (null)] type: str - src Local path to a file to copy to the remote server. This can be absolute or relative. If path is a directory, it is copied recursively. In this case, if path ends with "/", only inside contents of that directory are copied to destination. Otherwise, if it does not end with "/", the directory itself with all contents is copied. This behavior is similar to the `rsync' command line tool. [Default: (null)] type: path - unsafe_writes Influence when to use atomic operation to prevent data corruption or inconsistent reads from the target file. By default this module uses atomic operations to prevent data corruption or inconsistent reads from the target files, but sometimes systems are configured or just broken in ways that prevent this. One example is docker mounted files, which cannot be updated atomically from inside the container and can only be written in an unsafe manner. This option allows Ansible to fall back to unsafe methods of updating files when atomic operations fail (however, it doesn't force Ansible to perform unsafe writes). IMPORTANT! Unsafe writes are subject to race conditions and can lead to data corruption. [Default: False] type: bool version_added: 2.2 - validate The validation command to run before copying into place. The path to the file to validate is passed in via '%s' which must be present as in the examples below. The command is passed securely so shell features like expansion and pipes will not work. [Default: (null)] type: str NOTES: * The [copy] module recursively copy facility does not scale to lots (>hundreds) of files. SEE ALSO: * Module assemble The official documentation on the assemble module. https://docs.ansible.com/ansible/2.9/modules/assemble_module.html * Module fetch The official documentation on the fetch module. https://docs.ansible.com/ansible/2.9/modules/fetch_module.html * Module file The official documentation on the file module. https://docs.ansible.com/ansible/2.9/modules/file_module.html * Module synchronize The official documentation on the synchronize module. https://docs.ansible.com/ansible/2.9/modules/synchronize_module.html * Module template The official documentation on the template module. https://docs.ansible.com/ansible/2.9/modules/template_module.html * Module win_copy The official documentation on the win_copy module. https://docs.ansible.com/ansible/2.9/modules/win_copy_module.html AUTHOR: Ansible Core Team, Michael DeHaan METADATA: status: - stableinterface supported_by: core EXAMPLES: - name: Copy file with owner and permissions copy: src: /srv/myfiles/foo.conf dest: /etc/foo.conf owner: foo group: foo mode: '0644' - name: Copy file with owner and permission, using symbolic representation copy: src: /srv/myfiles/foo.conf dest: /etc/foo.conf owner: foo group: foo mode: u=rw,g=r,o=r - name: Another symbolic mode example, adding some permissions and removing others copy: src: /srv/myfiles/foo.conf dest: /etc/foo.conf owner: foo group: foo mode: u+rw,g-wx,o-rwx - name: Copy a new "ntp.conf file into place, backing up the original if it differs from the copied version copy: src: /mine/ntp.conf dest: /etc/ntp.conf owner: root group: root mode: '0644' backup: yes - name: Copy a new "sudoers" file into place, after passing validation with visudo copy: src: /mine/sudoers dest: /etc/sudoers validate: /usr/sbin/visudo -csf %s - name: Copy a "sudoers" file on the remote machine for editing copy: src: /etc/sudoers dest: /etc/sudoers.edit remote_src: yes validate: /usr/sbin/visudo -csf %s - name: Copy using inline content copy: content: '# This file was moved to /etc/other.conf' dest: /etc/mine.conf - name: If follow=yes, /path/to/file will be overwritten by contents of foo.conf copy: src: /etc/foo.conf dest: /path/to/link # link to /path/to/file follow: yes - name: If follow=no, /path/to/link will become a file and be overwritten by contents of foo.conf copy: src: /etc/foo.conf dest: /path/to/link # link to /path/to/file follow: no RETURN VALUES: dest: description: Destination file/path returned: success type: str sample: /path/to/file.txt src: description: Source file used for the copy on the target machine returned: changed type: str sample: /home/httpd/.ansible/tmp/ansible-tmp-1423796390.97-147729857856000/source md5sum: description: MD5 checksum of the file after running copy returned: when supported type: str sample: 2a5aeecc61dc98c4d780b14b330e3282 checksum: description: SHA1 checksum of the file after running copy returned: success type: str sample: 6e642bb8dd5c2e027bf21dd923337cbb4214f827 backup_file: description: Name of backup file created returned: changed and if backup=yes type: str sample: /path/to/file.txt.2015-02-12@22:09~ gid: description: Group id of the file, after execution returned: success type: int sample: 100 group: description: Group of the file, after execution returned: success type: str sample: httpd owner: description: Owner of the file, after execution returned: success type: str sample: httpd uid: description: Owner id of the file, after execution returned: success type: int sample: 100 mode: description: Permissions of the target, after execution returned: success type: str sample: 0644 size: description: Size of the target, after execution returned: success type: int sample: 1220 state: description: State of the target, after execution returned: success type: str sample: file ```
zhangky
2021年12月17日 13:51
分享文档
收藏文档
上一篇
下一篇
微信扫一扫
复制链接
手机扫一扫进行分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码