1. 简述
先从我自身的情况来说,我不是运维人员,并且对linux操作也不是特别熟悉,所以工作中我使用ansible基本就是在平常的自动化部署中,而使用最多的模块就是copy模块。我使用copy模块也主要是来替换生产环境的配置文件。所以,这里我主要介绍一下copy模块。说实话,对于其他模块,我接触的也不多。
2.copy 模块的用法
2.1 官方概念
我们先看官方文档怎么说的copy这个模块
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.
2.2 参数描述
3. 示例
3.1 将主机文件复制到远程机器上某个目录下
复制成功了。
这个时候如果我们再执行一次,可以看到结果发生了变化
在远程机器上也看到了这个文件
3.2 在主机上将文本内容复制到远程机器上文件中
3.2.1 执行命令
3.2.2 结果异常
FAILED! => {
“ansible_facts”: {
“discovered_interpreter_python”: “/usr/bin/python”
},
“changed”: false,
“checksum”: “a9dd8f985a0e22e8ce07dc2e9ec61d92fdeb96f9”,
“msg”: “Destination directory /test2 does not exist”
}