<p>For Ubuntu 16.04 should be something like this</p>

<pre><code>tasks
- name: Install Certbot.
  package: "name=letsencrypt state=present"
</code></pre>

<p>Or you can use a role from Github: <a href="https://github.com/geerlingguy/ansible-role-certbot" rel="nofollow noreferrer">https://github.com/geerlingguy/ansible-role-certbot</a></p>

CC BY-SA 4.0
2019-07-26T18:25:52.350Z
I'm fairly certain that the role mentioned does in fact install Certbot.
colan
CC BY-SA 4.0
2019-01-08T13:18:38.943Z
this does not install certbot
numediaweb
CC BY-SA 3.0
2018-01-23T09:58:25.877Z
2018-01-23T09:58:25.877Z
Maksim
<p>This is how I do it:</p>

<pre><code>- name: Add certbot repository
  apt_repository:
    repo: 'ppa:certbot/certbot'

- name: Install Certbot's Apache package
  apt:
    name: python-certbot-apache
    state: present
</code></pre>

CC BY-SA 4.0
2019-01-08T13:27:24.683Z
2019-01-08T13:27:24.683Z
numediaweb
<p>chipping in with ansible task to install letsencrypt certbot on debian stretch</p>

<pre><code>---
- name: Add "stretch-backports" to APT sources (required for Certbot)
  become: yes
  apt_repository:
    repo: deb http://httpredir.debian.org/debian stretch-backports main
    state: present
    update_cache: yes

- name: "Check LetsEncrypt/Certbot is installed"
  become: yes
  apt:
    name: 
      - certbot
      - python-certbot-apache # https://github.com/certbot/certbot/issues/3854
    state: present
    default_release: stretch-backports
    cache_valid_time: 3600
    update_cache: yes
</code></pre>

CC BY-SA 4.0
2019-10-03T13:02:19.680Z
2019-10-03T13:02:19.680Z
Rafa
<p>Here is the direct Ansible translation of your bash install script:</p>

<pre><code>- apt_repository:
    repo: 'ppa:certbot/certbot'

- apt:
    name: "{{ item }}"
    update_cache: yes
  with_items:
    - nginx
    - python-certbox-nginx
</code></pre>

CC BY-SA 4.0
2018-09-03T10:35:06.647Z
In Ubuntu 18.04 with Ansible 2.5.1, the first 2 rows raises: ``Warning: apt-key output should not be parsed``. However, I found that adding the repo is not needed in Ubuntu 18.04. You can install it directly with ``become: yes`` and ``apt: name: python-certbot-nginx``
Juha Untinen
CC BY-SA 3.0
2018-01-26T23:26:26.700Z
2018-01-26T23:26:26.700Z
Xiong Chiamiov
<p>This is how I install Certbot in a Bash script:</p>

<pre><code>apt-get update -y &amp;&amp; add-apt-repository ppa:certbot/certbot -y &amp;&amp; apt-get update -y
apt-get upgrade nginx python-certbot-nginx -y
</code></pre>

<hr>

<p>That's the playbook syntax I found to install Nginx in default conf:</p>

<pre><code>- hosts: localhost
    connection: local
    become: true

tasks:
    - name: install nginx
    apt: pkg=nginx state=installed update_cache=true
</code></pre>

<p>Is there no Ansible task to install Certbot as well, instead the above "heavier" Bash code?</p>

CC BY-SA 3.0
2018-01-23T06:37:57.823Z
Did you check ansible galaxy?
030
CC BY-SA 3.0
2018-01-23T06:39:13.830Z
No, just heard of that from you... :)
Arcticooling
CC BY-SA 3.0
2018-01-23T06:41:14.807Z
Hmm, just ran "certbot" in the Ansible Galaxy search engine... Sadly zero results.
Arcticooling
<ansible>
How to install Certbot via Ansible playbook?
Arcticooling
# How to install Certbot via Ansible playbook?

(Asked by: username_0 on 2018-01-23)

This is how I install Certbot in a Bash script:
apt-get update -y && add-apt-repository ppa:certbot/certbot -y && apt-get update -y
apt-get upgrade nginx python-certbot-nginx -y


That's the playbook syntax I found to install Nginx in default conf:
- hosts: localhost
    connection: local
    become: true

tasks:
    - name: install nginx
    apt: pkg=nginx state=installed update_cache=true

Is there no Ansible task to install Certbot as well, instead the above "heavier" Bash code?

**Tags:** ansible

> **Comments:**
> **username_1**: Did you check ansible galaxy?  
> **username_0**: No, just heard of that from you... :)  
> **username_0**: Hmm, just ran "certbot" in the Ansible Galaxy search engine... Sadly zero results.  

---

## 4 answers

### Answer by username_6 on 2018-01-26. Score: 5 | Accepted answer

Here is the direct Ansible translation of your bash install script:
- apt_repository:
    repo: 'ppa:certbot/certbot'

- apt:
    name: "{{ item }}"
    update_cache: yes
  with_items:
    - nginx
    - python-certbox-nginx

> **Comments:**
> **username_7**: In Ubuntu 18.04 with Ansible 2.5.1, the first 2 rows raises: ``Warning: apt-key output should not be parsed``. However, I found that adding the repo is not needed in Ubuntu 18.04. You can install it directly with ``become: yes`` and ``apt: name: python-certbot-nginx``  

---

### Answer by username_2 on 2018-01-23. Score: 4

For Ubuntu 16.04 should be something like this
tasks
- name: Install Certbot.
  package: "name=letsencrypt state=present"

Or you can use a role from Github: https://github.com/geerlingguy/ansible-role-certbot

> **Comments:**
> **username_4**: this does not install certbot  
> **username_3**: I'm fairly certain that the role mentioned does in fact install Certbot.  

---

### Answer by username_4 on 2019-01-08. Score: 0

This is how I do it:
- name: Add certbot repository
  apt_repository:
    repo: 'ppa:certbot/certbot'

- name: Install Certbot's Apache package
  apt:
    name: python-certbot-apache
    state: present


---

### Answer by username_5 on 2019-10-03. Score: -1

chipping in with ansible task to install letsencrypt certbot on debian stretch
---
- name: Add "stretch-backports" to APT sources (required for Certbot)
  become: yes
  apt_repository:
    repo: deb http://httpredir.debian.org/debian stretch-backports main
    state: present
    update_cache: yes

- name: "Check LetsEncrypt/Certbot is installed"
  become: yes
  apt:
    name: 
      - certbot
      - python-certbot-apache # https://github.com/certbot/certbot/issues/3854
    state: present
    default_release: stretch-backports
    cache_valid_time: 3600
    update_cache: yes


---

