- AnsibleFest
- Products
- Community
- Webinars & Training
- Blog

Documentation

# packet_sshkey – Create/delete an SSH key in Packet host

- Synopsis

- Requirements

- Parameters

- Examples

- Return Values

- Status

## Synopsis

- Create/delete an SSH key in Packet host.

- API is documented at https://www.packet.net/help/api/#page:ssh-keys,header:ssh-keys-ssh-keys-post.

## Requirements

The below requirements are needed on the host that executes this module.

- python >= 2.6

- packet-python

## Parameters

Parameter | Choices/Defaults | Comments
--- | --- | ---
auth_token - |  | Packet api token. You can also supply it in env var `PACKET_API_TOKEN`.
fingerprint - |  | Fingerprint of the key which you want to remove.
id - |  | UUID of the key which you want to remove.
key - |  | Public Key string ({type} {base64 encoded key} {description}).
key_file - |  | File with the public key.
label - |  | Label for the key. If you keep it empty, it will be read from key string.
state - | Choices: present ← absent | Indicate desired state of the target.

## Examples

    # All the examples assume that you have your Packet API token in env var PACKET_API_TOKEN.
    # You can also pass the api token in module param auth_token.

    - name: create sshkey from string
      hosts: localhost
      tasks:
        packet_sshkey:
          key: "{{ lookup('file', 'my_packet_sshkey.pub') }}"

    - name: create sshkey from file
      hosts: localhost
      tasks:
        packet_sshkey:
          label: key from file
          key_file: ~/ff.pub

    - name: remove sshkey by id
      hosts: localhost
      tasks:
        packet_sshkey:
          state: absent
          id: eef49903-7a09-4ca1-af67-4087c29ab5b6

## Return Values

Common return values are documented here, the following are the fields unique to this module:

Key | Returned | Description
--- | --- | ---
changed boolean | always | True if a sshkey was created or removed. Sample: True
sshkeys list | always | Information about sshkeys that were createe/removed. Sample: [{'fingerprint': '5c:93:74:7c:ed:07:17:62:28:75:79:23:d6:08:93:46', 'id': '41d61bd8-3342-428b-a09c-e67bdd18a9b7', 'key': 'ssh-dss tomk@hp2', 'label': 'mynewkey33'}]

## Status

- This module is not guaranteed to have a backwards compatible interface. [preview]

- This module is maintained by the Ansible Community. [community]

### Authors

- Tomas Karasek (@t0mk) <tom.to.the.k@gmail.com>

Hint

If you notice any issues in this documentation, you can edit this document to improve it.