community.general.github_key 模块 – 管理 GitHub 访问密钥
注意
此模块是 community.general 集合 (版本 10.1.0) 的一部分。
如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.general。
要在 playbook 中使用它,请指定:community.general.github_key。
概要
- 创建、删除或更新 GitHub 访问密钥。 
参数
| 参数 | 注释 | 
|---|---|
| SSH 密钥名称 | |
| SSH 公钥值。当  | |
| 是否删除密钥、确保密钥存在或更新其值。 选项 
 | |
| 具有列出和创建公钥权限的 GitHub 访问令牌。 | 
属性
| 属性 | 支持 | 描述 | 
|---|---|---|
| 支持:完全支持 | 可以在  | |
| 支持:不支持 | 处于差异模式时,将返回有关已更改内容(或可能需要在  | 
示例
- name: Read SSH public key to authorize
  ansible.builtin.shell: cat /home/foo/.ssh/id_rsa.pub
  register: ssh_pub_key
- name: Authorize key with GitHub
  local_action:
    module: github_key
    name: Access Key for Some Machine
    token: '{{ github_access_token }}'
    pubkey: '{{ ssh_pub_key.stdout }}'
# Alternatively, a single task can be used reading a key from a file on the controller
- name: Authorize key with GitHub
  community.general.github_key:
    name: Access Key for Some Machine
    token: '{{ github_access_token }}'
    pubkey: "{{ lookup('ansible.builtin.file', '/home/foo/.ssh/id_rsa.pub') }}"
返回值
常见的返回值已在 此处 记录,以下是此模块特有的字段
| 键 | 描述 | 
|---|---|
| 已删除的密钥对象的数组。仅在 state=absent 时出现 返回:当 state=absent 时 示例: | |
| 关于刚刚创建的密钥的元数据。仅在 state=present 时出现 返回:成功 示例: | |
| 与指定名称匹配的密钥数组。仅在 state=present 时出现 返回:当 state=present 时 示例: | 
