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

    - 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?

  • Did you check ansible galaxy?
    – 030
    Commented Jan 23, 2018 at 6:37
  • No, just heard of that from you... :) Commented Jan 23, 2018 at 6:39
  • Hmm, just ran "certbot" in the Ansible Galaxy search engine... Sadly zero results. Commented Jan 23, 2018 at 6:41

4 Answers 4


Here is the direct Ansible translation of your bash install script:

- apt_repository:
    repo: 'ppa:certbot/certbot'

- apt:
    name: "{{ item }}"
    update_cache: yes
    - nginx
    - python-certbox-nginx
  • 2
    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 Commented Sep 3, 2018 at 10:35

For Ubuntu 16.04 should be something like this

- name: Install Certbot.
  package: "name=letsencrypt state=present"

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

  • this does not install certbot
    – numediaweb
    Commented Jan 8, 2019 at 13:18
  • I'm fairly certain that the role mentioned does in fact install Certbot.
    – colan
    Commented Jul 26, 2019 at 18:25

This is how I do it:

- name: Add certbot repository
    repo: 'ppa:certbot/certbot'

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

chipping in with ansible task to install letsencrypt certbot on debian stretch

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.