You are reading an unmaintained version of the Ansible documentation. Unmaintained Ansible versions can contain unfixed security vulnerabilities (CVE). Please upgrade to a maintained version. See the latest Ansible documentation.
authorized_key - Adds or removes an SSH authorized key¶
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
(added in 1.9)
no
no
yes
no
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.
key
yes
The SSH public key(s), as a string or (since 1.9) url (https://github.com/username.keys)
key_options
(added in 1.4)
no
A string of ssh key options to be prepended to the key in the authorized_keys file
manage_dir
no
yes
yes
no
Whether this module should manage the directory of the authorized key file. If set, 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. See the example below.
path
no
(homedir)+/.ssh/authorized_keys
Alternate path to the authorized_keys file
state
no
present
present
absent
Whether the given key (with the given key_options) should or should not be in the file
user
yes
The username on the remote host whose authorized_keys file will be modified
validate_certs
(added in 2.1)
no
yes
yes
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.
-name:Set authorized key took from fileauthorized_key:user:charliestate:presentkey:"{{lookup('file','/home/charlie/.ssh/id_rsa.pub')}}"-name:Set authorized key took from urlauthorized_key:user:charliestate:presentkey:https://github.com/charlie.keys-name:Set authorized key in alternate locationauthorized_key:user:charliestate:presentkey:"{{lookup('file','/home/charlie/.ssh/id_rsa.pub')}}"path:/etc/ssh/authorized_keys/charliemanage_dir:False-name:Set up multiple authorized keysauthorized_key:user:deploystate:presentkey:'{{item}}'with_file:-public_keys/doe-jane-public_keys/doe-john-name:Set authorized key defining key optionsauthorized_key:user:charliestate:presentkey:"{{lookup('file','/home/charlie/.ssh/id_rsa.pub')}}"key_options:'no-port-forwarding,from="10.0.1.1"'-name:Set authorized key without validating the TLS/SSL certificatesauthorized_key:user:charliestate:presentkey:https://github.com/user.keysvalidate_certs:False-name:Set authorized key, removing all the authorized key already setauthorized_key:user:rootkey:'{{item}}'state:presentexclusive:Truewith_file:-public_keys/doe-jane-name:Set authorized key for user ubuntu copying it from current userauthorized_key:user:ubuntustate:presentkey:"{{lookup('file',lookup('env','HOME')+'/.ssh/id_rsa.pub')}}"
For more information about Red Hat’s this support of this module, please
refer to this knowledge base article<https://access.redhat.com/articles/rhel-top-support-policies>