ansible剧本在主机之一上失败

时间:2019-12-21 09:29:59

标签: 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

1 个答案:

答案 0 :(得分:0)

手动运行时,您的环境可能已设置为具有正确的ssh密钥以访问遥控器。使用cron时,ssh密钥可能不可用。