ansible模块os_keypair从不返回private_key的值

时间:2019-09-20 19:27:37

标签: ansible openstack openstack-nova openstack-horizon

我想使用ansible模块os_keypairopenstack生成ssh密钥对。为此,我使用以下代码:

- name: create openstack ssh key pair
  os_keypair:
    name: my-key
    auth: my authentication parameters
    auth_type: password
    state: present
  register: key

从头开始运行该代码(即之前没有生成密钥)时,它的工作方式是在openstack中生成并上传了密钥。 但是,我需要私钥才能通过ansible执行后续操作(例如,将私钥复制到文件的local_action)。模块文档说私钥可用作返回值之一。检查我的返回值时,我得到以下信息:

"key": {
   "created_at": null, 
   "fingerprint": null, 
   "id": null, 
   "is_deleted": null, 
   "location": null, 
   "name": null, 
   "private_key": null, 
   "public_key": null, 
   "type": "ssh", 
   "user_id": null
}

这让我有些困惑。那是正常行为还是该模块有问题?

[更新] 这是一个完整的剧本,再现了这种行为:

---
- hosts: localhost

  become_user: ansible

  become: True

  tasks:

    - name: create openstack ssh key pair
      os_keypair:
        name: my-key
        auth:
          auth_url: http://cloudsrv1.ill.fr:5000/v3
          username: ansible-test
          password: 1234
          project_name: k8s
          project_domain_name: default
          user_domain_name: default
        auth_type: password
        state: present
      register: key

    - debug:
        var: key

使用python3作为python解释器执行的剧本。

输出:

TASK [debug] ********************************************************************************************************************
ok: [localhost] => {
    "key": {
        "changed": true, 
        "failed": false, 
        "id": "my-key", 
        "key": {
            "created_at": null, 
            "fingerprint": null, 
            "id": null, 
            "is_deleted": null, 
            "location": null, 
            "name": null, 
            "private_key": null, 
            "public_key": null, 
            "type": "ssh", 
            "user_id": null
        }
    }
}

,但是会生成密钥,从openstack快照可以看出。

enter image description here

1 个答案:

答案 0 :(得分:0)

pip安装了最新的openstacksdk软件包(0.36),从而解决了该问题。