python - 无法将文件从主机复制到 ansible 服务器
问题描述
我正在尝试用ansible做一个简单的过程,但是在尝试运行这个剧本时我失败了,我只想把用户临时目录中的现有文件复制回里面的ansible服务器etc/ansible/files
路径和权限
root@ansible:/etc/ansible/files# pwd
/etc/ansible/files
root@ansible:/etc/ansible/files# ls -ltr ../
total 24
-rw-r--r-- 1 root root 535 mar 27 11:23 ansible.cfg
-rw-r--r-- 1 root root 188 mar 27 15:41 hosts
drwxr-xr-x 5 root root 4096 mar 27 15:42 roles
drwxr-xr-x 2 root root 4096 mar 27 15:42 group_vars
drwxrwxrwx 2 root root 4096 mar 27 16:59 files
drwxr-xr-x 3 root root 4096 mar 27 17:01 playbook
剧本
- name: auto_collect_pingprobe
hosts: "{{ affected_host }}"
gather_facts: no
tasks:
- block:
- name: 'Copy net connect'
fetch:
src: '%temp%\net_connect.cfg'
dest: '/etc/ansible/files/net_connect.cfg'
flat: yes
rescue:
- fail:
msg: "Failure detected in playbook"
输出
fatal: [192.168.238.12]: FAILED! => {
"msg": "failed to transfer file to \"/etc/ansible/files/net_connect.cfg\""
}
TASK [fail] *************************************************************************************************************************************************
task path: /etc/ansible/playbook/GEN_AUTO_COLLECT_HOST_AVAILABLE.yml:22
fatal: [192.168.238.12]: FAILED! => {
"changed": false,
"msg": "Failure detected in playbook"
}
解决方案
可能会发生两件事。
- 您可能在受控节点上没有 root 权限,请确保您
--become
在调用笔记本时使用该标志(或使用等效的权限提升)。 %temp%
变量可能不是从环境中读取的。尝试将src
字符串替换为'{{ lookup("env", "temp") }}\net_connect.cfg'
.
推荐阅读
- c - 为什么tasklet_action()函数中会调用BUG?
- mongodb - 不同的结构类型切片作为函数的参数
- javascript - 在 react 和 node.js 应用程序中,styles.css 并未仅应用于一页
- javascript - JavaScript xPath
- java - 无法从给定代码访问类错误?
- xml - 在 Spark 中爆炸复杂的嵌套 XML
- firefox - Tampermonkey (Firefox) 用户脚本存储位置
- javascript - 使用 vanilla js 进行表单验证
- haskell - 如何防止指数运算符(^)的默认实现
- python - 按下按钮时如何在 QFormLayout 中添加更多行