# webserver secure

**URL:** <https://forum.ansible.com/t/webserver-secure/28342>\
**Category:** Ansible Project\
**Created:** [August 16, 2018, 5:14pm UTC](https://forum.ansible.com/t/webserver-secure/28342 "2018-08-16T17:14:54Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [August 16, 2018, 5:14pm UTC](https://forum.ansible.com/t/webserver-secure/28342/1 "2018-08-16T17:14:54Z")

</div>

Hi,

Trying to create an ec2 instance using ansible. which will host a normal webserver but not sure on how to add the self signed certificate to the http - webserver using ansible.

Also how to redirect all the http request to https one using ansible. Could you please suggest. thank you.

---

<div class="post-metadata">

**Author:** ![Jonathan\_Lozada\_De\_L](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@Jonathan\_Lozada\_De\_L](https://forum.ansible.com/u/Jonathan_Lozada_De_L)\
**Post date:** [August 16, 2018, 5:19pm UTC](https://forum.ansible.com/t/webserver-secure/28342/2 "2018-08-16T17:19:29Z")

</div>

Coach,

how do you currently do your certs? you can either use the letsencrypt modules, use copy to put it on webserver you build or use get\_url. You can also do the same for the webserver config you are using. You can also template the config file.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [August 16, 2018, 5:28pm UTC](https://forum.ansible.com/t/webserver-secure/28342/3 "2018-08-16T17:28:46Z")

</div>

Hi,

> how do you currently do your certs? you can either use the letsencrypt  
> modules,

the letsencrypt module was renamed to acme\_certificate (to not violate  
Let's Encrypt's trademark) for Ansible 2.6.  
(The renamed module's documentation: [https://docs.ansible.com/ansible/latest/modules/acme\_certificate\_module.html](https://docs.ansible.com/ansible/latest/modules/acme_certificate_module.html))

Note that it's also possible to use acme-tiny  
([https://github.com/diafygi/acme-tiny/](https://github.com/diafygi/acme-tiny/)) with Ansible using the  
openssl\_certificate module  
([https://docs.ansible.com/ansible/latest/modules/openssl\_certificate\_module.html](https://docs.ansible.com/ansible/latest/modules/openssl_certificate_module.html)).  
Depending on your use-case, this can be much simpler than using the  
acme\_certificate module. There are also roles encapsulating the  
acme\_certificate module and make it easier to use (for example, one by  
myself: [https://github.com/felixfontein/acme-certificate/](https://github.com/felixfontein/acme-certificate/)).

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [August 17, 2018, 4:11am UTC](https://forum.ansible.com/t/webserver-secure/28342/4 "2018-08-17T04:11:03Z")

</div>

thanks Jonathan for reciprocating, i use the openssl on the OS to generate the pem file and then the crt file but i am checking on how to achieve this on ansible.

just like a private self signed certificate for internal use for the webserver that will be provisioned.

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [August 18, 2018, 4:34am UTC](https://forum.ansible.com/t/webserver-secure/28342/5 "2018-08-18T04:34:34Z")

</div>

Could you please suggest with your expert advise.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [August 18, 2018, 11:44am UTC](https://forum.ansible.com/t/webserver-secure/28342/6 "2018-08-18T11:44:59Z")

</div>

You can do it with the same command that you usually use, Ansible can run OS commands with the command and the shell modules.

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [August 18, 2018, 12:19pm UTC](https://forum.ansible.com/t/webserver-secure/28342/7 "2018-08-18T12:19:42Z")

</div>

Hi Coach,

you can also use the following modules:  
&nbsp;&nbsp;\* openssl\_privatekey to generate the private key  
&nbsp;&nbsp;&nbsp;&nbsp;([https://docs.ansible.com/ansible/latest/modules/openssl\_privatekey\_module.html](https://docs.ansible.com/ansible/latest/modules/openssl_privatekey_module.html))  
&nbsp;&nbsp;\* openssl\_csr to generate the CSR  
&nbsp;&nbsp;&nbsp;&nbsp;([https://docs.ansible.com/ansible/latest/modules/openssl\_csr\_module.html](https://docs.ansible.com/ansible/latest/modules/openssl_csr_module.html))  
&nbsp;&nbsp;\* openssl\_certificate to generate the self-signed certificate  
&nbsp;&nbsp;&nbsp;&nbsp;([https://docs.ansible.com/ansible/latest/modules/openssl\_certificate\_module.html](https://docs.ansible.com/ansible/latest/modules/openssl_certificate_module.html))

Please check out the documentation, it also contains example on how to  
use the modules.

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [August 19, 2018, 7:11am UTC](https://forum.ansible.com/t/webserver-secure/28342/8 "2018-08-19T07:11:00Z")

</div>

thanks kai…

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [August 19, 2018, 7:11am UTC](https://forum.ansible.com/t/webserver-secure/28342/9 "2018-08-19T07:11:56Z")

</div>

thanks felix for the module

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [August 20, 2018, 5:17am UTC](https://forum.ansible.com/t/webserver-secure/28342/10 "2018-08-20T05:17:14Z")

</div>

Could you please help … am unable to retrieve the public ip address of the ec2 instance to add it to the host inventory…

- name: Create an ec2 instance  
ec2:  
key\_name: “{{ keypair }}”  
group: sg\_webserver\_group  
instance\_type: “{{ instance\_type}}”  
image: “{{ ami }}”  
wait: true  
region: “{{ region }}”  
assign\_public\_ip: yes  
register: ec2

- debug: **var=ec2.instances.public\_ip** ( **or var=ec2.public\_ip doesnt give the public ip rather gives undefined variable but whereas var=ec2** gives all the details)

- name: Add the newly created host  
add\_host:  
name: “{{ item.public\_ip }}”  
groups: webserver  
with\_items: “{{ ec2.instances }}”

Thank you

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [August 20, 2018, 3:54pm UTC](https://forum.ansible.com/t/webserver-secure/28342/11 "2018-08-20T15:54:16Z")

</div>

any valuable inputs from you experts …not sure if calling it the right way after register the variable…

---

<div class="post-metadata">

**Author:** ![felixfontein](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/felixfontein/32/7530_2.png) [@felixfontein](https://forum.ansible.com/u/felixfontein)\
**Post date:** [August 20, 2018, 4:29pm UTC](https://forum.ansible.com/t/webserver-secure/28342/12 "2018-08-20T16:29:20Z")

</div>

Hi Coach,

you might want to start a new thread for a new question about something  
completely different. Re-using the old thread might cause people who  
could otherwise help you ignore your question because they think it is  
about the old topic. Also, the people who answered to the old thread  
earlier might now know enough to answer your new question. That's the  
case for me and your new question, as I've never used the ec2 module.

Cheers,  
Felix

---

<div class="post-metadata">

**Author:** ![coach.rhca](https://avatars.discourse-cdn.com/v4/letter/c/c57346/32.png) [@coach.rhca](https://forum.ansible.com/u/coach.rhca)\
**Post date:** [August 20, 2018, 5:24pm UTC](https://forum.ansible.com/t/webserver-secure/28342/13 "2018-08-20T17:24:57Z")

</div>

sure
