ansible playbook在一个主机上失败

ansible playbook在一个主机上失败,ansible,Ansible,我在ansible剧本中发现以下错误。机器xxx.xxx.xxx.xxx是debian 10机器。Playbook是通过cron运行的。但是如果我手动运行Playbook,它就成功了 failed: [xxx.xxx.xxx.xxx] (item={u'path': u'/home/sdf/.ssh', u'state': u'directory', u'mode': u'0700'}) => {"item": {"mode": "0700", "path": "/home/sdf/.ss

我在ansible剧本中发现以下错误。机器xxx.xxx.xxx.xxx是debian 10机器。Playbook是通过cron运行的。但是如果我手动运行Playbook,它就成功了

failed: [xxx.xxx.xxx.xxx] (item={u'path': u'/home/sdf/.ssh', u'state': u'directory', u'mode': u'0700'}) => {"item": {"mode": "0700", "path": "/home/sdf/.ssh", "state": "directory"}, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", "unreachable": true}
下面是我的剧本

---
- name: touch sdf known_hosts file
  file: path={{ item.path }} state={{ item.state }} mode={{ item.mode }} owner=sdf group=sdf
  with_items:
    - { path: '/home/sdf/.ssh', state: 'directory', mode: '0700' }
    - { path: '/home/sdf/.ssh/known_hosts', state: 'touch', mode: '0600' }
- name: add known_hosts for sdf user
  lineinfile: dest=/home/sdf/.ssh/known_hosts line="{{ item }}"
  with_items:
    - x1
    - x2
    - x3

手动运行时,您的环境可能已设置为具有正确的ssh密钥来访问远程服务器。使用cron时,ssh密钥可能不可用。

之前的相同剧本运行良好。现在它不起作用了
权限被拒绝(公钥、密码)
最可能的情况是ssh客户端(ansible运行)没有正确的ssh密钥来访问服务器。需要检查它为什么找不到或使用它。要么它尝试使用默认的ssh密钥(/.ssh/id_rsa),要么某个地方明确指定了另一个密钥。解决这个问题的一个(复杂的)方法是使用
-vvvv
args运行ansible,这将显示/输出ansible执行的ssh命令。然后使用
-vvvv
运行相同的ssh命令将显示它试图用来访问远程服务器的密钥。