opensslでコマンド一発で秘密鍵と自己証明書を作成する例です。
openssl req -new -newkey rsa:2048 -sha1 -x509 -nodes \
-set_serial 1 \
-days 365 \
-subj "/C=JP/ST=Osaka/L=Osaka City/CN=example.com" \
-out /etc/pki/tls/certs/example.com.crt \
-keyout /etc/pki/tls/private/example.com.key
Ansibleのplaybookの例
https://github.com/hnakamur/ansible-playbooks/blob/c4f05a64cddd4275a437c68ae2439e429d56a9d6/roles/common/tasks/self_signed_certificate.yml