LIP-Computing.ssl-certs
ansible-role-ssl-certs
Générer et/ou déployer un certificat SSL
Disponible sur Ansible Galaxy : LIP-Computing.ssl-certs
Exemples
Exemple pour générer un certificat SSL auto-signé
- hosts: all
roles:
- LIP-Computing.ssl-certs
Cela créera le certificat et la clé privée dans :
/etc/ssl/myserver.mydomain.com.key
/etc/ssl/myserver.mydomain.com.pem
Exemple pour déployer un certificat SSL
Deux exemples de playbooks sont montrés ci-dessous :
- hosts: all
roles:
- role: LIP-Computing.ssl-certs
ssl_certs_common_name: "example.com"
- hosts: all
roles:
- role: LIP-Computing.ssl-certs
ssl_certs_common_name: "myhost.mydomain"
ssl_certs_country: "PT"
ssl_certs_locality: "Lisbonne"
ssl_certs_organization: "LIP"
ssl_certs_state: "Lisbonne"
ssl_certs_path_owner: "root"
ssl_certs_path_group: "root"
ssl_certs_generate_dh_param: true
Le certificat doit être placé dans files/ssl/example.com.key
et files/ssl/example.com.pem
. Si
ils n'existent pas, ils seront générés comme un certificat auto-signé à
/etc/ssl/example.com.key
et /etc/ssl/example.com.key
en utilisant le nom commun fourni.
Exemple pour déployer un certificat SSL en utilisant des fichiers clé/pem locaux
- hosts: all
roles:
- role: LIP-Computing.ssl-certs
ssl_certs_local_privkey_path: '/path/to/example.com.key'
ssl_certs_local_cert_path: '/path/to/example.com.pem'
Exemple pour déployer un certificat SSL stocké dans des variables
Un certificat SSL et une clé ne sont que du texte qui peut être stocké en tant que variable, ce qui est utile lors de l'utilisation d'ansible vault.
Exemple de données de variable, notez comment le bloc de texte est indenté. Cela est nécessaire pour insérer correctement le texte via le module de modèle.
ssl_certs_local_privkey_data: |
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAu2uhv2cjoN4F3arUZ5cDrwuxf3koCwrKSK75as0WZoxYrpyw
Lyx9ldyD4nGabVep0R/uAgQ/HqEf2jC7WIvGcEq8bHB9PyEEWzT8IjKQX0YTc//4
gkHBkpyU0fVrj5nkc30EIbcbH4RHRDwye4VhP/iCPchDG7OqvCyOdm8=
-----END RSA PRIVATE KEY-----
ssl_certs_local_cert_data: |
-----BEGIN CERTIFICATE-----
MIIDmzCCAoOgAwIBAgIJAKWMlgLwrBzXMA0GCSqGSIb3DQEBCwUAMGQxCzAJBgNV
QAL3naEfBSZBl0tBohuxn8Xd3yLPuKGUOk3pSL1IJy0Ca6p+QwjkaZUd9X3gf1V2
SEfYSaGPvfIlSuHIshno
-----END CERTIFICATE-----
Il suffit ensuite d'inclure le rôle comme dans le premier exemple.
Exemple d'utilisation de ce rôle avec mon rôle Nginx : jdauphant.nginx
- hosts: all
roles:
- LIP-Computing.ssl-certs
ssl_certs_generate_dh_param: true
- role: jdauphant.nginx
nginx_configs:
ssl:
- ssl_certificate_key {{ssl_certs_privkey_path}}
- ssl_certificate {{ssl_certs_cert_path}}
- ssl_dhparam {{ssl_certs_dhparam_path}}
nginx_sites:
default:
- listen 443 ssl
- server_name _
- root "/usr/share/nginx/html"
- index index.html
ansible-galaxy install LIP-Computing.ssl-certs