Ansible Generate_ssh_key Module

 admin
  • Adds or removes SSH authorized keys for particular user accounts.
  1. Ansible Add Public Ssh Key
  2. Ansible Generate_ssh_key Module 3
ParameterChoices/DefaultsComments
comment
string
Change the comment on the public key.
Rewriting the comment is useful in cases such as fetching it from GitHub or GitLab.
If no comment is specified, the existing comment will be kept.
exclusive
boolean
    Choices:
  • yes
Whether to remove all other non-specified keys from the authorized_keys file.
Multiple keys can be specified in a single key string value by separating them by newlines.
This option is not loop aware, so if you use with_ , it will be exclusive per iteration of the loop.
If you want multiple keys in the file you need to pass them all to key in a single batch as mentioned above.
follow
boolean
    Choices:
  • no
  • yes
key
The SSH public key(s), as a string or (since Ansible 1.9) url (https://github.com/username.keys).
key_options
-
A string of ssh key options to be prepended to the key in the authorized_keys file.
manage_dir
boolean
    Choices:
  • no
Whether this module should manage the directory of the authorized key file.
If set to yes, the module will create the directory, as well as set the owner and permissions of an existing directory.
Be sure to set manage_dir=no if you are using an alternate directory for authorized_keys, as set with path, since you could lock yourself out of SSH access.
path
Alternate path to the authorized_keys file.
When unset, this value defaults to ~/.ssh/authorized_keys.
state
string
    Choices:
  • absent
Whether the given key (with the given key_options) should or should not be in the file.
user
string / required
The username on the remote host whose authorized_keys file will be modified.
validate_certs
boolean
    Choices:
  • no
This only applies if using a https url as the source of the keys.
If set to no, the SSL certificates will not be validated.
This should only set to no used on personally controlled sites using self-signed certificates as it avoids verifying the source site.
Prior to 2.1 the code worked as if this was set to yes.
Ansible argument_spec

Ansible works by connecting to your nodes and pushing out small programs, called 'Ansible modules' to them. These programs are written to be resource models of the desired state of the system. Ansible then executes these modules (over SSH by default), and removes them when finished. Ansible 2.0 has recently been released, and with it comes support for version 2 of the DigitalOcean API.This means that you can use Ansible to not only provision your web applications, but also to provision and manage your Droplets automatically. While Ansible has an authorizedkeys module specifically for handling these files, it has problems with quotes in restricted keys. The third task reads the jinja2 template for sshdconfig, adds the necessary information, and copies the file to the server. 7 thoughts on “How To Manage SSH Keys Using Ansible”. The above example run the shell module recursively till the module’s result has “all systems go” in its stdout or the task has been retried for 5 times with a delay of 10 seconds. The default value for “retries” is 3 and “delay” is 5. The task returns the results returned by the last task run. Apr 28, 2018 Join GitHub today. GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs. Designed for multi-tier deployments since day one, Ansible models your IT infrastructure by describing how all of your systems inter-relate, rather than just managing one system at a time.


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

KeyReturnedDescription
exclusive
boolean
success
If the key has been forced to be exclusive or not.

key
string
success
Sample:
key_optionsuccess
Key options related to the key.

keyfile
string
success
Sample:
manage_dirsuccess
Whether this module managed the directory of the authorized key file.

True
path
string
success
statesuccess
Whether the given key (with the given key_options) should or should not be in the file

present
unique
boolean
success
usersuccess
The username on the remote host whose authorized_keys file will be modified

user
validate_certs
boolean
success
This only applies if using a https url as the source of the keys. If set to no, the SSL certificates will not be validated.

True

  • This module is not guaranteed to have a backwards compatible interface. [preview]
  • This module is maintained by the Ansible Core Team. [core]

Red Hat Support¶

More information about Red Hat’s support of this module is available from this Red Hat Knowledge Base article.

Authors¶

  • Ansible Core Team

Ansible Add Public Ssh Key

Hint

Ansible Generate_ssh_key Module 3

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