Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move steps to their own files. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tasks/custom_command.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

- name: Run custom acme.sh command
command: ./acme.sh {{ item.custom_command }}
args:
chdir: "~/.acme.sh"
environment: "{{ item.dns_provider_api_keys | default(acme_sh_default_dns_provider_api_keys) }}"
loop: "{{ acme_sh_domains }}"
become_user: "{{ acme_sh_become_user }}"
14 changes: 14 additions & 0 deletions tasks/force_renew_cert.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---

- name: Force renew acme.sh certificate(s)
command: >-
./acme.sh --renew -d {{ item.domains | first }} --force
{{ "--debug" if item.debug | default(acme_sh_default_debug) else "" }}
{{ item.extra_flags_renew | default(acme_sh_default_extra_flags_renew) }}
args:
chdir: "~/.acme.sh"
loop: "{{ acme_sh_domains }}"

become_user: "{{ acme_sh_become_user }}"
register: renew_result
failed_when: renew_result.rc != 0 and "Reload error for" not in renew_result.stderr
48 changes: 48 additions & 0 deletions tasks/install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---

- name: Install dependencies
apt:
name: "{{ item }}"
update_cache: True
cache_valid_time: "{{ acme_sh_apt_cache_time }}"
loop: ["cron", "git", "wget"]

- name: Create git clone path
file:
path: "{{ acme_sh_git_clone_dest | dirname }}"
state: "directory"
owner: "{{ acme_sh_become_user }}"
group: "{{ acme_sh_become_user }}"
mode: "0755"

- name: Git clone https://github.com/Neilpang/acme.sh
git:
repo: "{{ acme_sh_git_url }}"
version: "{{ acme_sh_git_version }}"
dest: "{{ acme_sh_git_clone_dest }}"
update: "{{ acme_sh_git_update }}"
become_user: "{{ acme_sh_become_user }}"

- name: Install acme.sh
command: >-
./acme.sh --install --log
--days {{ acme_sh_renew_time_in_days }}
{{ "--accountemail " + acme_sh_account_email if acme_sh_account_email else "" }}
args:
chdir: "{{ acme_sh_git_clone_dest }}"
creates: "~/.acme.sh/acme.sh"
become_user: "{{ acme_sh_become_user }}"

- name: Create certificate path
file:
path: "{{ acme_sh_copy_certs_to_path }}"
state: "directory"
owner: "{{ acme_sh_become_user }}"
group: "{{ acme_sh_become_user }}"
mode: "0755"

- name: Determine if acme.sh is installed (post-install)
stat:
path: "~/.acme.sh/acme.sh"
register: is_acme_sh_installed
become_user: "{{ acme_sh_become_user }}"
27 changes: 27 additions & 0 deletions tasks/install_cert.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---

- name: Ensure installed certificates have correct user / group ownership
file:
path: "{{ acme_sh_copy_certs_to_path }}/{{ item.domains | first }}*"
group: "{{ acme_sh_become_user }}"
owner: "{{ acme_sh_become_user }}"
loop:
- "{{ acme_sh_domains }}"

- name: Install acme.sh certificate(s)
command: >-
./acme.sh --install-cert -d {{ item.domains | first }}
--key-file {{ acme_sh_copy_certs_to_path }}/{{ item.domains | first }}.key
--fullchain-file {{ acme_sh_copy_certs_to_path }}/{{ item.domains | first }}.pem
--reloadcmd "{{ item.install_cert_reloadcmd | default(acme_sh_default_install_cert_reloadcmd) }}"
{{ "--debug" if item.debug | default(acme_sh_default_debug) else "" }}
{{ item.extra_flags_install_cert | default(acme_sh_default_extra_flags_install_cert) }}
args:
chdir: "~/.acme.sh"
loop: "{{ acme_sh_domains }}"
loop_control:
index_var: domains_index
become_user: "{{ acme_sh_become_user }}"
register: install_cert_result
changed_when: issue_result.results[domains_index].changed or renew_result.results[domains_index].changed
failed_when: install_cert_result.rc != 0 and "Reload error for" not in install_cert_result.stderr
22 changes: 22 additions & 0 deletions tasks/issue_cert.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---

- name: Issue acme.sh certificate(s) (this will sleep for dns_sleep seconds)
command: >-
./acme.sh --issue -d {{ item.domains | join(" -d ") }}
--dns {{ item.dns_provider | default(acme_sh_default_dns_provider) }}
--dnssleep {{ item.dns_sleep | default(acme_sh_default_dns_sleep) }}
{{ "--force" if item.force_issue | default(acme_sh_default_force_issue) else "" }}
{{ "--staging" if item.staging | default(acme_sh_default_staging) else "" }}
{{ "--debug" if item.debug | default(acme_sh_default_debug) else "" }}
{{ "--pre-hook " + '"' + item.issue_pre_hook | default(acme_sh_default_issue_pre_hook) + '"' if item.issue_pre_hook | default(acme_sh_default_issue_pre_hook) else "" }}
{{ "--post-hook " + '"' + item.issue_post_hook | default(acme_sh_default_issue_post_hook) + '"' if item.issue_post_hook | default(acme_sh_default_issue_post_hook) else "" }}
{{ "--renew-hook " + '"' + item.issue_renew_hook | default(acme_sh_default_issue_renew_hook) + '"' if item.issue_renew_hook | default(acme_sh_default_issue_renew_hook) else "" }}
{{ item.extra_flags_issue | default(acme_sh_default_extra_flags_issue) }}
args:
chdir: "~/.acme.sh"
environment: "{{ item.dns_provider_api_keys | default(acme_sh_default_dns_provider_api_keys) }}"
loop: "{{ acme_sh_domains }}"
become_user: "{{ acme_sh_become_user }}"
register: issue_result
changed_when: issue_result.rc == 0 and "Cert success" in issue_result.stdout
failed_when: issue_result.rc != 0 and "Domains not changed" not in issue_result.stdout
14 changes: 14 additions & 0 deletions tasks/list_cert.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---

- name: Register acme.sh certificate information
command: ./acme.sh --list
args:
chdir: "~/.acme.sh"
changed_when: False
register: list_domains
become_user: "{{ acme_sh_become_user }}"

- name: List acme.sh certificate information
debug:
msg: "{{ list_domains.stdout_lines }}"
when: acme_sh_list_domains and not acme_sh_uninstall
Loading