Ansible本地配置文件无法识别密钥?

时间:2017-01-04 15:32:44

标签: ubuntu vagrant ansible vagrantfile

我有一个vagrant框,其中precise32已启动并正在运行。

我在~/Workspace/vagrans/ansible文件夹中,其中有一个文件ansible.cfg,其中包含以下条目:

[defaults]
inventory = ./dms/dev
private_key_file = /home/pkaramol/Workspace/vagrans/vagrant/precise32/.vagrant/machines/default/virtualbox/private_key 

这有效:

ansible -m ping all --private-key=/home/pkaramol/Workspace/vagrans/vagrant/precise32/.vagrant/machines/default/virtualbox/private_key -u vagrant
tsrv1 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

这不是:

ansible-playbook playbooks/testplay.yml 

PLAY ***************************************************************************

TASK [setup] *******************************************************************
fatal: [tsrv1]: UNREACHABLE! => {"changed": false, "msg": "ERROR! SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue", "unreachable": true}

PLAY RECAP *********************************************************************
tsrv1                      : ok=0    changed=0    unreachable=1    failed=0   

这是剧本:

- hosts: testservers
  tasks:
    - name: just pinging
      ping:

这是库存文件

[testservers]
tsrv1

我一定是想念......(?)......

2 个答案:

答案 0 :(得分:1)

无需在配置文件和Playbook之间拆分凭据,如you suggested

您可以在ansible.cfg旁边的private_key_file中使用remote-user参数:

[defaults]
inventory = ./dms/dev
remote-user = vagrant
private_key_file = /home/pkaramol/Workspace/vagrans/vagrant/precise32/.vagrant/machines/default/virtualbox/private_key

答案 1 :(得分:0)

只需将剧本中的remote_user明确设置为vagrant

- hosts: testservers
  remote_user: vagrant
  tasks:
    - name: just pinging
      ping: