Ansible Generate Ssh Key Pair
Ansible Generate Ssh Key Pair 3,6/5 207 reviews
  1. Ansible - Creating users and copying ssh keypair files to the remote server - main.yml.
  2. Mar 10, 2018  ssh-keygen tool is used to generate private/public key pair for ssh. By default, tool generates the private (idrsa) and public (idrsa.pub) keys in /.ssh/ directory. We can generate the keys.
  3. This is helpful when generating a SSH key pair and distribute the resulting public key. At the moment one needs to run a command task that outputs keyfile.pub and use its stdout to get hold of the public key. This could be much more elegant.
Ansible Generate Ssh Key Pair

SSH Key based authentication setup using ansible. In this post, we are going to see how to enable the SSH key-based authentication between two remote servers using ansible by creating and exchanging the keys. We are going to use ansible built-in modules like Shell and Copy and Fetch and most importantly authorizedkey.

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

  • boto
  • boto3
  • python >= 2.6
ParameterChoices/DefaultsComments
aws_access_key
string
AWS access key. If not set then the value of the AWS_ACCESS_KEY_ID, AWS_ACCESS_KEY or EC2_ACCESS_KEY environment variable is used.
aws_secret_key
AWS secret key. If not set then the value of the AWS_SECRET_ACCESS_KEY, AWS_SECRET_KEY, or EC2_SECRET_KEY environment variable is used.
debug_botocore_endpoint_logs
added in 2.8
    Choices:
  • yes
Use a botocore.endpoint logger to parse the unique (rather than total) 'resource:action' API calls made during a task, outputing the set to the resource_actions key in the task results. Use the aws_resource_action callback to output to total list made during a playbook. The ANSIBLE_DEBUG_BOTOCORE_LOGS environment variable may also be used.
ec2_url
string
Url to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints). Ignored for modules where region is required. Must be specified for all other modules if region is not used. If not set then the value of the EC2_URL environment variable, if any, is used.
force
boolean
    Choices:
  • no
Force overwrite of already existing key pair if key has changed.
key_material
-
name
Name of the key pair.
profile
string
Uses a boto profile. Only works with boto >= 2.24.0.
region
string
The AWS region to use. If not specified then the value of the AWS_REGION or EC2_REGION environment variable, if any, is used. See http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region
security_token
AWS STS security token. If not set then the value of the AWS_SECURITY_TOKEN or EC2_SECURITY_TOKEN environment variable is used.
state
    Choices:
  • present
  • absent
validate_certs
    Choices:
  • no
  • yes
When set to 'no', SSL certificates will not be validated for boto versions >= 2.6.0.
wait
boolean
    Choices:
  • yes
Wait for the specified action to complete before returning. This option has no effect since version 2.5.
wait_timeout
-
Default:
How long before wait gives up, in seconds. This option has no effect since version 2.5.

Note

  • If parameters are not set within the module, the following environment variables can be used in decreasing order of precedence AWS_URL or EC2_URL, AWS_ACCESS_KEY_ID or AWS_ACCESS_KEY or EC2_ACCESS_KEY, AWS_SECRET_ACCESS_KEY or AWS_SECRET_KEY or EC2_SECRET_KEY, AWS_SECURITY_TOKEN or EC2_SECURITY_TOKEN, AWS_REGION or EC2_REGION
  • Ansible uses the boto configuration file (typically ~/.boto) if no credentials are provided. See https://boto.readthedocs.io/en/latest/boto_config_tut.html
  • AWS_REGION or EC2_REGION can be typically be used to specify the AWS region, when required, but this can also be configured in the boto config file

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

KeyReturnedDescription
changed
boolean
always
Sample:
keyalways
details of the keypair (this is set to null when state is absent)

fingerprint
string
when state is present
Sample:
b0:22:49:61:d9:44:9d:0c:7e:ac:8a:32:93:21:6c:e8:fb:59:62:43
name
string
when state is present
Sample:
private_keywhen a new keypair is created by AWS (key_material is not provided)
private key of a newly created keypair

-----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKC.. -----END RSA PRIVATE KEY-----
msg
string
always
Sample:

  • This module is guaranteed to have backward compatible interface changes going forward. [stableinterface]
  • This module is maintained by the Ansible Community. [community]

Authors¶

Ansible Generate Ssh Key

  • Vincent Viallet (@zbal)
  • Prasad Katti (@prasadkatti)

Hint

The initial base of Photoshop’s naming scheme is on the version numbers. For example, the eighth version number of Photoshop was Photoshop CS, and the ninth was Photoshop CS2. Photoshop cs 8 key generator Whereas, in October 2002, following the introduction of Creative Suite branding, every new version of Adobe Photoshop Crack has a design with CS plus a number.

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

  • Create, register and remove SSH keys.
  • If no key was found and no public key was provided and a new SSH private/public key pair will be created and the private key will be returned.

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

  • python >= 2.6
  • cs >= 0.6.10
ParameterChoices/DefaultsComments
account
string
api_http_method
    Choices:
  • get
  • post
HTTP method used to query the API endpoint.
If not given, the CLOUDSTACK_METHOD env variable is considered.
As the last option, the value is taken from the ini config file, also see the notes.
api_key
API key of the CloudStack API.
If not given, the CLOUDSTACK_KEY env variable is considered.
As the last option, the value is taken from the ini config file, also see the notes.
api_region
string
Default:
Name of the ini section in the cloustack.ini file.
If not given, the CLOUDSTACK_REGION env variable is considered.
api_secret
string
If not set, the CLOUDSTACK_SECRET env variable is considered.
As the last option, the value is taken from the ini config file, also see the notes.
api_timeout
integer
If not given, the CLOUDSTACK_TIMEOUT env variable is considered.
As the last option, the value is taken from the ini config file, also see the notes.
api_url
URL of the CloudStack API e.g. https://cloud.example.com/client/api.
If not given, the CLOUDSTACK_ENDPOINT env variable is considered.
As the last option, the value is taken from the ini config file, also see the notes.
domain
string
name
Name of public key.
project
string
Name of the project the public key to be registered in.
public_key
string
state
    Choices:
  • present
  • absent

Note

  • Ansible uses the cs library’s configuration method if credentials are not provided by the arguments api_url, api_key, api_secret. Configuration is read from several locations, in the following order. The CLOUDSTACK_ENDPOINT, CLOUDSTACK_KEY, CLOUDSTACK_SECRET and CLOUDSTACK_METHOD. CLOUDSTACK_TIMEOUT environment variables. A CLOUDSTACK_CONFIG environment variable pointing to an .ini file. A cloudstack.ini file in the current working directory. A .cloudstack.ini file in the users home directory. Optionally multiple credentials and endpoints can be specified using ini sections in cloudstack.ini. Use the argument api_region to select the section name, default section is cloudstack. See https://github.com/exoscale/cs for more information.
  • A detailed guide about cloudstack modules can be found in the CloudStack Cloud Guide.
  • This module supports check mode.

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

KeyReturnedDescription
fingerprint
string
success
Sample:
idsuccess
UUID of the SSH public key.

a6f7a5fc-43f8-11e5-a151-feff819cdc9f
name
string
success
Sample:
private_keychanged
Private key of generated SSH keypair.

-----BEGIN RSA PRIVATE KEY----- MII..8tO -----END RSA PRIVATE KEY-----

  • This module is guaranteed to have backward compatible interface changes going forward. [stableinterface]
  • This module is maintained by the Ansible Community. [community]

Authors¶

  • René Moser (@resmo)

Hint

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