4

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 '18 at 6:37
  • No, just heard of that from you... :) – Arcticooling Jan 23 '18 at 6:39
  • Hmm, just ran "certbot" in the Ansible Galaxy search engine... Sadly zero results. – Arcticooling Jan 23 '18 at 6:41
6

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
  • 1
    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 Sep 3 '18 at 10:35
5

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 '19 at 13:18
  • I'm fairly certain that the role mentioned does in fact install Certbot. – colan Jul 26 '19 at 18:25
1

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
0

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, privacy policy and cookie policy

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