{"id":62,"date":"2021-07-05T17:58:40","date_gmt":"2021-07-05T17:58:40","guid":{"rendered":"https:\/\/elevenguard.com\/blog\/?p=62"},"modified":"2021-07-14T10:49:12","modified_gmt":"2021-07-14T10:49:12","slug":"ansible-openssl","status":"publish","type":"post","link":"https:\/\/elevenguard.com\/blog\/ansible-openssl\/","title":{"rendered":"Setting Up a Self-Signed Certificate in Ansible"},"content":{"rendered":"\n<p>The primary purpose of DevOps is to automate code deployments and testing for more rapid software development. In most environments, <a href=\"https:\/\/elevenguard.com\/blog\/monitor-ssl-certificate-expiry\/\">SSL\/TLS certificates<\/a> are necessary for data encryption to avoid eavesdropping and man-in-the-middle attacks. For development environments, an SSL\/TLS certificate might not be necessary, but you need one installed to avoid errors and bypass certificate validation in production code. A self-signed certificate will remediate development issues with SSL\/TLS certificates so that they can be bypassed during testing. <strong>Ansible OpenSSL<\/strong> allows you to install a self-signed certificate for your development environment, but you first must create and install it.<br><\/p>\n\n\n\n<h2 id=\"self-signed-vs-certificate-authority-ca\" class=\"wp-block-heading\">Self-Signed vs. Certificate Authority (CA)<\/h2>\n\n\n\n<p>Before using a self-signed certificate, you should know the difference between installing a certificate from a CA and using self-signed certificates. Self-signed certificates are untrusted and should only be used in development environments. They are a workaround for SSL\/TLS validation while you develop an application.<\/p>\n\n\n\n<p>In a production environment, you generate private keys to create a CSR (certified signing request) signed and validated by a CA that then tells users and applications that the certificate should be trusted. If you use a self-signed certificate in production, users will receive warnings not to trust the host. Self-signed certificates can be used in phishing attacks, so modern browsers warn users not to trust a host without a valid CA-signed certificate.<\/p>\n\n\n\n<p>In a development environment, a self-signed certificate might be necessary, but know that they should never be used in production.<br><\/p>\n\n\n\n<h2 id=\"creating-a-self-signed-certificate\" class=\"wp-block-heading\">Creating a Self-Signed Certificate<\/h2>\n\n\n\n<p>The first step before certificate creation is to ensure Ansible is installed. Run the following command to get the Ansible version:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ ansible --version<\/pre>\n\n\n\n<p>Next, you need to install the pyOpenSSL dependency to generate keys. Run the following command to install pyOpenSSL with pip (replace pip3 with pip if you are using version 2.x):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sudo pip3 install pyOpenSSL<\/pre>\n\n\n\n<p>Ansible relies on three modules to create keys and set up the self-signed certificate. Ensure that these three modules are installed:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>openssl_csr<\/li><li>openssl_privatekey<\/li><li>openssl_certificate<\/li><\/ul>\n\n\n\n<p>To generate a certificate, you first need to create private keys. Private keys are what decrypts data on the server, and they are used to create public keys used by client applications (e.g., web browsers). The initial step in encrypted communication uses an asymmetric cipher (e.g., RSA) to transfer a symmetric key to the server, which is why you need a private-public key pair. The client machine uses the server\u2019s public keys to encrypt the symmetric key and passes it across the network to the server. The server decrypts the symmetric key with its private keys, and then a session is created where all data between the client and the host are encrypted with the symmetric key. Without the initial private-public key pair, the symmetric key would be vulnerable to eavesdropping and could be intercepted in a man-in-the-middle attack.<\/p>\n\n\n\n<p>Creation of a self-signed certificate uses the following general steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Create private keys using openssl_privatekey<\/li><li>Create a CSR using openssl_csr<\/li><li>Generate the self-signed certificate using openssl_certificate<\/li><\/ul>\n\n\n\n<p>The first step is to generate private keys, shown below:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">openssl_privatekey:<br>path: \/etc\/ansible\/ansible_pvt.key<br>size: 2048<\/pre>\n\n\n\n<p>The above command creates a 2048-bit private RSA key. You can eliminate the size variable to create the default 4096-bit key, but this is likely not necessary in development. RSA is standard for most key generations, but you can alternatively use the type: parameter to use a different algorithm.<\/p>\n\n\n\n<p>With the private key created, you can now create a CSR using the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">openssl_csr:<br>path: \/etc\/ansible\/ansible_server.csr<br>privatekey_path: \/etc\/ansible\/ansible_pvt.key<\/pre>\n\n\n\n<p>In the above command, the private key is used to create the ansible_server.csr file. In a production environment, you would send this CSR file to the certificate authority of your choice to sign the key and verify that it\u2019s valid, but since we\u2019re creating a self-signed certificate, the next step is to install a self-signed certificate generated with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> openssl_certificate:\n provider: selfsigned\n path: \/etc\/ansible\/ansible_server.crt\n privatekey_path: \/etc\/ansible\/ansible_server.key\n csr_path: \/etc\/ansible\/ansible_server.csr<\/pre>\n\n\n\n<p>After this step, you can use the CRT file to set up encrypted connections on your server. Every certificate has an expiration date, usually a year from the time it was created. You must renew the certificate before it expires. Should you forget to renew the certificate, you will receive errors in production or in your development environment. Forgetting to renew an expired certificate can crash services and cause critical downtime for applications running in production or development. Common <a href=\"https:\/\/elevenguard.com\/blog\/err_ssl_version_or_cipher_mismatch\/\">browsers such as Chrome warn users<\/a> when server certificates have expired. You can avoid these errors by <a href=\"https:\/\/elevenguard.com\/\">monitoring your SSL\/TLS certificates expiration dates<\/a> and renewing them before they expire.<\/p>\n","protected":false},"excerpt":{"rendered":"A self-signed certificate will remediate development issues with SSL\/TLS certificates on test environments.\n","protected":false},"author":3,"featured_media":81,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[8],"class_list":{"0":"post-62","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-howto","8":"tag-ansible"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Setting Up a Self-Signed Certificate in Ansible - DevOps Squad<\/title>\n<meta name=\"description\" content=\"Ansible OpenSSL allows you to install a self-signed certificate for your development environment, but you first must create and install it.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/elevenguard.com\/blog\/ansible-openssl\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Setting Up a Self-Signed Certificate in Ansible - DevOps Squad\" \/>\n<meta property=\"og:description\" content=\"Ansible OpenSSL allows you to install a self-signed certificate for your development environment, but you first must create and install it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/elevenguard.com\/blog\/ansible-openssl\/\" \/>\n<meta property=\"og:site_name\" content=\"DevOps Squad\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-05T17:58:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-14T10:49:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/elevenguard.com\/blog\/wp-content\/uploads\/2021\/07\/ansible-openssl-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Noah Rotheray\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Noah Rotheray\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/elevenguard.com\/blog\/ansible-openssl\/\",\"url\":\"https:\/\/elevenguard.com\/blog\/ansible-openssl\/\",\"name\":\"Setting Up a Self-Signed Certificate in Ansible - DevOps Squad\",\"isPartOf\":{\"@id\":\"https:\/\/elevenguard.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/elevenguard.com\/blog\/ansible-openssl\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/elevenguard.com\/blog\/ansible-openssl\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/elevenguard.com\/blog\/wp-content\/uploads\/2021\/07\/ansible-openssl-1.jpg\",\"datePublished\":\"2021-07-05T17:58:40+00:00\",\"dateModified\":\"2021-07-14T10:49:12+00:00\",\"author\":{\"@id\":\"https:\/\/elevenguard.com\/blog\/#\/schema\/person\/c281aa6af5ee1c4ae5339eb3f9c68631\"},\"description\":\"Ansible OpenSSL allows you to install a self-signed certificate for your development environment, but you first must create and install it.\",\"breadcrumb\":{\"@id\":\"https:\/\/elevenguard.com\/blog\/ansible-openssl\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/elevenguard.com\/blog\/ansible-openssl\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/elevenguard.com\/blog\/ansible-openssl\/#primaryimage\",\"url\":\"https:\/\/elevenguard.com\/blog\/wp-content\/uploads\/2021\/07\/ansible-openssl-1.jpg\",\"contentUrl\":\"https:\/\/elevenguard.com\/blog\/wp-content\/uploads\/2021\/07\/ansible-openssl-1.jpg\",\"width\":1920,\"height\":1024},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/elevenguard.com\/blog\/ansible-openssl\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/elevenguard.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Setting Up a Self-Signed Certificate in Ansible\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/elevenguard.com\/blog\/#website\",\"url\":\"https:\/\/elevenguard.com\/blog\/\",\"name\":\"DevOps Squad\",\"description\":\"A community of hand-picked ninjas that share their expertise and  help the DevOps community to grow.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/elevenguard.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/elevenguard.com\/blog\/#\/schema\/person\/c281aa6af5ee1c4ae5339eb3f9c68631\",\"name\":\"Noah Rotheray\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/elevenguard.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/69fd89d0f6c10294164aa4dd162938eb18dc6c17a485439134e75569b21367a9?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/69fd89d0f6c10294164aa4dd162938eb18dc6c17a485439134e75569b21367a9?s=96&d=mm&r=g\",\"caption\":\"Noah Rotheray\"},\"description\":\"Born to find Open Source solutions to everything :)\",\"url\":\"https:\/\/elevenguard.com\/blog\/author\/noah-rotheray\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Setting Up a Self-Signed Certificate in Ansible - DevOps Squad","description":"Ansible OpenSSL allows you to install a self-signed certificate for your development environment, but you first must create and install it.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/elevenguard.com\/blog\/ansible-openssl\/","og_locale":"en_US","og_type":"article","og_title":"Setting Up a Self-Signed Certificate in Ansible - DevOps Squad","og_description":"Ansible OpenSSL allows you to install a self-signed certificate for your development environment, but you first must create and install it.","og_url":"https:\/\/elevenguard.com\/blog\/ansible-openssl\/","og_site_name":"DevOps Squad","article_published_time":"2021-07-05T17:58:40+00:00","article_modified_time":"2021-07-14T10:49:12+00:00","og_image":[{"width":1920,"height":1024,"url":"https:\/\/elevenguard.com\/blog\/wp-content\/uploads\/2021\/07\/ansible-openssl-1.jpg","type":"image\/jpeg"}],"author":"Noah Rotheray","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Noah Rotheray","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/elevenguard.com\/blog\/ansible-openssl\/","url":"https:\/\/elevenguard.com\/blog\/ansible-openssl\/","name":"Setting Up a Self-Signed Certificate in Ansible - DevOps Squad","isPartOf":{"@id":"https:\/\/elevenguard.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/elevenguard.com\/blog\/ansible-openssl\/#primaryimage"},"image":{"@id":"https:\/\/elevenguard.com\/blog\/ansible-openssl\/#primaryimage"},"thumbnailUrl":"https:\/\/elevenguard.com\/blog\/wp-content\/uploads\/2021\/07\/ansible-openssl-1.jpg","datePublished":"2021-07-05T17:58:40+00:00","dateModified":"2021-07-14T10:49:12+00:00","author":{"@id":"https:\/\/elevenguard.com\/blog\/#\/schema\/person\/c281aa6af5ee1c4ae5339eb3f9c68631"},"description":"Ansible OpenSSL allows you to install a self-signed certificate for your development environment, but you first must create and install it.","breadcrumb":{"@id":"https:\/\/elevenguard.com\/blog\/ansible-openssl\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/elevenguard.com\/blog\/ansible-openssl\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/elevenguard.com\/blog\/ansible-openssl\/#primaryimage","url":"https:\/\/elevenguard.com\/blog\/wp-content\/uploads\/2021\/07\/ansible-openssl-1.jpg","contentUrl":"https:\/\/elevenguard.com\/blog\/wp-content\/uploads\/2021\/07\/ansible-openssl-1.jpg","width":1920,"height":1024},{"@type":"BreadcrumbList","@id":"https:\/\/elevenguard.com\/blog\/ansible-openssl\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/elevenguard.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Setting Up a Self-Signed Certificate in Ansible"}]},{"@type":"WebSite","@id":"https:\/\/elevenguard.com\/blog\/#website","url":"https:\/\/elevenguard.com\/blog\/","name":"DevOps Squad","description":"A community of hand-picked ninjas that share their expertise and  help the DevOps community to grow.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/elevenguard.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/elevenguard.com\/blog\/#\/schema\/person\/c281aa6af5ee1c4ae5339eb3f9c68631","name":"Noah Rotheray","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/elevenguard.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/69fd89d0f6c10294164aa4dd162938eb18dc6c17a485439134e75569b21367a9?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/69fd89d0f6c10294164aa4dd162938eb18dc6c17a485439134e75569b21367a9?s=96&d=mm&r=g","caption":"Noah Rotheray"},"description":"Born to find Open Source solutions to everything :)","url":"https:\/\/elevenguard.com\/blog\/author\/noah-rotheray\/"}]}},"_links":{"self":[{"href":"https:\/\/elevenguard.com\/blog\/wp-json\/wp\/v2\/posts\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elevenguard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elevenguard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elevenguard.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/elevenguard.com\/blog\/wp-json\/wp\/v2\/comments?post=62"}],"version-history":[{"count":5,"href":"https:\/\/elevenguard.com\/blog\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"predecessor-version":[{"id":69,"href":"https:\/\/elevenguard.com\/blog\/wp-json\/wp\/v2\/posts\/62\/revisions\/69"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/elevenguard.com\/blog\/wp-json\/wp\/v2\/media\/81"}],"wp:attachment":[{"href":"https:\/\/elevenguard.com\/blog\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elevenguard.com\/blog\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elevenguard.com\/blog\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}