5

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?

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

4 Answers 4

5

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
1
  • 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 Sep 3, 2018 at 10:35
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

2
  • this does not install certbot
    – numediaweb
    Jan 8, 2019 at 13:18
  • I'm fairly certain that the role mentioned does in fact install Certbot.
    – colan
    Jul 26, 2019 at 18:25
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
-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

Your Answer

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

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