我正在使用 OpenStack ansible 模块部署到 Rackspace Cloud。
我在创建 SSH 密钥对时遇到问题。它会创建公钥并将其安装在主机上。但是我看到返回的 JSON 不包含 private_key 键值对。
- name: SSH key check
os_keypair:
auth:
auth_url: "{{ os_auth_url }}"
project_name: "{{ os_project_name }}"
username: "{{ os_username }}"
password: "{{ os_password }}"
state: present
region_name: "{{ os_region }}"
name: "{{ os_key_name }}"
register: keypair
- name: Create local public
local_action:
module: copy
content: "{{ keypair.key.public_key }}"
dest: "~/.ssh/{{ keypair.key.name }}.pub"
- name: Create local private key
local_action:
module: copy
content: "{{ keypair.key.private_key }}"
dest: "~/.ssh/{{ keypair.key.name }}"
ignore_errors: True
密钥对变量的值:
{
"changed": false,
"id": "openstack",
"key": {
"public_key": "ssh-rsa AAAAByouknowwhatapublickeylookslikeyouknowwhatapublickeylookslikeyouknowwhatapublickeylookslikeyouknowwhatapublickeylookslikeyouknowwhatapublickeylookslikeyouknowwhatapublickeylookslikeyouknowwhatapublickeylookslikeyouknowwhatapublickeylookslikeyouknowwhatapublickeylookslikeyouknowwhatapublickeylookslikeyouknowwhatapublickeylookslikeyouknowwhatapublickeylookslikeJiln Generated-by-Nova",
"NAME_ATTR": "name",
"name": "openstack",
"fingerprint": "89:e9:3d:s0:m3:nu:mb:3r:41:d5:09:8b:a9:b8:50:65",
"id": "openstack",
"human_id": null,
"request_ids": [],
"HUMAN_ID": false,
"x_openstack_request_ids": []
}
}
正如你所见,private_key
不存在。根据文档它应该归还它。
对这一切来说都很新,所以要温柔一点:)
答案1
我相信该os_keypair
模块没有对系统进行任何更改。变量的内容keypair
表明:
{
"changed": false,
...
}
ansible 文档对返回 a 是这样说的private_key
。
仅当为用户生成密钥对时(例如,创建密钥对并且未指定公钥时)。
如果公钥存在,我认为模块不会生成新的密钥对。