Article Directory
Warm up:
Concepts that need to be noted in advance when using ansible and its copy module:
A) 需要明确ansible管理管端,执行的用户
root: 拥有所有权限
普通用户:只拥有本身的权限
B)使用copy模块,涉及到copy master数据到remote,必须保证
ansible执行者,对这些ansible机器中数据文件,具有w
(可copy)权限
C)客户端(ansible被控端),必须确认client用户,对远程机器
具有对应权限
<client用户怎么确定???>
1)/etc/ansible/hosts中ansible_ssh_user设置
2)名字行执行:ansible web -m shell -a "xx" -u client用户
The ansible copy module uses:
Copy module parameter description:
parameter | Description |
---|---|
src | The local object file or folder copied to the remote host can be an absolute path or a relative path |
dest | Local object files or folders copied to the remote host |
mode | Set permissions for copy objects |
owner | Setting owner of copy object |
group | Copy target settings belong to group |
backup | When the file exists, you can choose to back up the source file before overwriting. Setting value: yes/no The default is yes |
force | Whether to force coverage. Setting value: yes/no default is no |
Copy the file to the remote machine and set the "owner/group/permission"
ansible all -i hosts -m copy -a "src=./list dest=/root/ owner=china group=mockuser mode=0777"
Copy the file to the remote machine and back it up:
ansible all -i hosts -m copy -a "src=./list。file dest=/tmp backup=yes"
【参数说明】
hosts:类似/etc/ansible/hosts
backup=yes表示:远程机器如果存在旧的list.file那么先备份原来的
Create a file for the remote machine and write data:
# 在目录下创建文件并写入内容dest 参数对应的值必须是一个文件,而不能是一个路径。
ansible -i hosts all -m copy -a 'content="aaa\nbbb\n" dest=/tmp/my.file'