[英]Ansible: copying file from master to web machine
我尝试使用 ansible 使用以下命令行复制文件,但出现凭据错误。
ansible -i./hosts all -m copy -a "src=/etc/hosts dest=/tmp/hosts" -k
SSH 密码:
192.168.0.166 | UNREACHABLE: => { "changed", false: "msg": "无效/不正确的密码,权限被拒绝。请再试一次": "unreachable": true
但是,在运行 ping 时,我得到了正确的 output。
ansible -i./hosts all -u ansible -m ping
192.168.0.122 | 成功 => {“改变”:假,“平”:“乒乓”
ssh 公钥肯定会复制到服务器中。 据我检查,linux 文件夹中的权限没问题。 我需要用这条线运行它,而不是使用剧本。 你有什么主意吗? 我需要指定用户吗?
像这样创建主机文件
[root@chfapp directory]# cat host
[remote]
10.x.x.x
创建无密码 SSH
ssh-copy-id root@10.x.x.x
然后使用此命令进行 ping
[root@chfapp directory]# ansible -i host all -m ping
10.x.x.x | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
如果你得到 pong 然后只尝试复制命令
[root@chfapp directory]# ansible -i ./host all -m copy -a "src=/etc/hosts dest=/tmp/hosts" -k
SSH password:
10.x.x.x | CHANGED => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"checksum": "afc8b584b5d97582547c5ec261c5e407b551d06a",
"dest": "/tmp/hosts",
"gid": 0,
"group": "root",
"md5sum": "1316425243d92c3ddbadda6096d1d105",
"mode": "0644",
"owner": "root",
"size": 245,
"src": "/root/.ansible/tmp/ansible-tmp-1616767392.68-28343-81423044115547/source",
"state": "file",
"uid": 0
}
似乎 ssh 密钥存储在远程计算机上的“ansible”用户下,因此在执行 ansible 时需要指定用户:
ansible -u ansible
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.