This repository has been archived by the owner on Mar 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example systemd unit files and ansible roles
- Loading branch information
Showing
22 changed files
with
247 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
- name: example play | ||
hosts: all | ||
vars: | ||
keyvault_certdeploy_vault_name: some-keyvault-name | ||
roles: | ||
- { role: keyvault-certdeploy.cert, cert: "example.org" } | ||
- { role: keyvault-certdeploy.cert, cert: "example.net" } |
3 changes: 3 additions & 0 deletions
3
examples/ansible/roles/keyvault-certdeploy.cert/meta/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
--- | ||
dependencies: | ||
- { role: keyvault-certdeploy.common } |
9 changes: 9 additions & 0 deletions
9
examples/ansible/roles/keyvault-certdeploy.cert/tasks/cert.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
- name: add keyvault-certdeploy config for {{ cert }} | ||
template: | ||
src: cert.yml.j2 | ||
dest: "{{ keyvault_certdeploy_configd }}/50_{{ cert }}.yml" | ||
mode: 0400 | ||
notify: | ||
- build keyvault-certdeploy config | ||
|
2 changes: 2 additions & 0 deletions
2
examples/ansible/roles/keyvault-certdeploy.cert/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
- { import_tasks: cert.yml, tags: [ ssl, ssl-cert, cert, certs, acme, acme-cert ] } |
19 changes: 19 additions & 0 deletions
19
examples/ansible/roles/keyvault-certdeploy.cert/templates/cert.yml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# {{ ansible_managed }} | ||
- cn: {{ cert }} | ||
keyalgo: rsa | ||
privkey: /etc/ssl/private/{{ cert }}.rsa.key.pem | ||
cert: /etc/ssl/certs/{{ cert }}.rsa.crt.pem | ||
chain: /etc/ssl/certs/{{ cert }}.rsa.chain.pem | ||
fullchain: /etc/ssl/certs/{{ cert }}.rsa.fullchain.pem | ||
fullchainprivkey: /etc/ssl/private/{{ cert }}.rsa.fullchain.key.pem | ||
hooks: | ||
- run-parts {{ keyvault_certdeploy_hooksd }} | ||
- cn: {{ cert }} | ||
keyalgo: ecdsa | ||
privkey: /etc/ssl/private/{{ cert }}.ecdsa.key.pem | ||
cert: /etc/ssl/certs/{{ cert }}.ecdsa.crt.pem | ||
chain: /etc/ssl/certs/{{ cert }}.ecdsa.chain.pem | ||
fullchain: /etc/ssl/certs/{{ cert }}.ecdsa.fullchain.pem | ||
fullchainprivkey: /etc/ssl/private/{{ cert }}.ecdsa.fullchain.key.pem | ||
hooks: | ||
- run-parts {{ keyvault_certdeploy_hooksd }} |
1 change: 1 addition & 0 deletions
1
examples/ansible/roles/keyvault-certdeploy.common/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
keyvault_certdeploy_vault_url: https://{{ keyvault_certdeploy_vault_name }}.vault.azure.net/ |
5 changes: 5 additions & 0 deletions
5
examples/ansible/roles/keyvault-certdeploy.common/files/hooks/apache2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ -f /usr/sbin/apache2ctl ]]; then | ||
systemctl reload apache2 | ||
fi |
5 changes: 5 additions & 0 deletions
5
examples/ansible/roles/keyvault-certdeploy.common/files/hooks/haproxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ -f /usr/sbin/haproxy ]]; then | ||
systemctl reload haproxy | ||
fi |
5 changes: 5 additions & 0 deletions
5
examples/ansible/roles/keyvault-certdeploy.common/files/hooks/nginx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ -f /usr/sbin/nginx ]]; then | ||
systemctl reload nginx | ||
fi |
7 changes: 7 additions & 0 deletions
7
examples/ansible/roles/keyvault-certdeploy.common/handlers/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# assemble main | ||
- name: assemble keyvault-certdeploy config | ||
assemble: | ||
src: "{{ keyvault_certdeploy_configd }}" | ||
dest: "{{ keyvault_certdeploy_config }}" | ||
mode: 0400 | ||
listen: build keyvault-certdeploy config |
84 changes: 84 additions & 0 deletions
84
examples/ansible/roles/keyvault-certdeploy.common/tasks/keyvault-certdeploy.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
- name: download package | ||
get_url: | ||
url: "{{ keyvault_certdeploy_url }}" | ||
checksum: "{{ keyvault_certdeploy_checksum }}" | ||
dest: /usr/local/src/keyvault-certdeploy.tar.gz | ||
register: download | ||
- name: install | ||
block: | ||
- name: extract files | ||
unarchive: | ||
src: /usr/local/src/keyvault-certdeploy.tar.gz | ||
remote_src: yes | ||
dest: /usr/local/sbin | ||
exclude: | ||
- LICENSE | ||
when: download.changed | ||
- name: set permissions | ||
file: | ||
path: /usr/local/sbin/keyvault-certdeploy | ||
owner: root | ||
group: root | ||
mode: 0550 | ||
- name: create config source directory | ||
file: | ||
path: "{{ keyvault_certdeploy_configd }}" | ||
state: directory | ||
owner: root | ||
group: root | ||
mode: 0500 | ||
- name: copy cert vault configuration | ||
template: | ||
src: vault.yml.j2 | ||
dest: "{{ keyvault_certdeploy_configd }}/00_vault.yml" | ||
notify: | ||
- build keyvault-certdeploy config | ||
- name: create hooks directory | ||
file: | ||
path: "{{ keyvault_certdeploy_hooksd }}" | ||
state: directory | ||
owner: root | ||
group: root | ||
mode: 0500 | ||
- name: deploy default hooks | ||
copy: | ||
src: hooks/{{ item }} | ||
dest: "{{ keyvault_certdeploy_hooksd }}/10_{{ item }}" | ||
mode: 0500 | ||
loop: | ||
- apache2 | ||
- haproxy | ||
- nginx | ||
- name: deploy service environment file | ||
template: | ||
src: env.j2 | ||
dest: "{{ keyvault_certdeploy_config_root }}/.env" | ||
owner: root | ||
group: root | ||
mode: 0400 | ||
- name: deploy systemd services | ||
template: | ||
src: "{{ item }}.j2" | ||
dest: /etc/systemd/system/{{ item }} | ||
owner: root | ||
group: root | ||
mode: 0444 | ||
loop: | ||
- keyvault-certdeploy.service | ||
- keyvault-certdeploy-periodic.service | ||
- keyvault-certdeploy-periodic.timer | ||
- name: enable services | ||
systemd: | ||
name: "{{ item }}.service" | ||
enabled: yes | ||
daemon_reload: yes | ||
loop: | ||
- keyvault-certdeploy | ||
- keyvault-certdeploy-periodic | ||
- name: enable timer | ||
systemd: | ||
name: keyvault-certdeploy-periodic.timer | ||
enabled: yes | ||
state: started | ||
daemon_reload: yes |
2 changes: 2 additions & 0 deletions
2
examples/ansible/roles/keyvault-certdeploy.common/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
- { import_tasks: keyvault-certdeploy.yml, tags: [ keyvault-certdeploy ] } |
9 changes: 9 additions & 0 deletions
9
examples/ansible/roles/keyvault-certdeploy.common/templates/env.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ++++++++++++++++++++++++++++++++++++++++++++ | ||
# DO NOT EDIT MANUALLY | ||
# ++++++++++++++++++++++++++++++++++++++++++++ | ||
# {{ ansible_managed }} | ||
{% if keyvault_certdeploy_auth is defined %} | ||
AZURE_TENANT_ID={{ keyvault_certdeploy_auth.tenant_id }} | ||
AZURE_CLIENT_ID={{ keyvault_certdeploy_auth.client_id }} | ||
AZURE_CLIENT_SECRET={{ keyvault_certdeploy_auth.client_secret }} | ||
{% endif %} |
11 changes: 11 additions & 0 deletions
11
...nsible/roles/keyvault-certdeploy.common/templates/keyvault-certdeploy-periodic.service.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# ++++++++++++++++++++++++++++++++++++++++++++ | ||
# DO NOT EDIT MANUALLY | ||
# ++++++++++++++++++++++++++++++++++++++++++++ | ||
# {{ ansible_managed }} | ||
[Unit] | ||
Description=Fetch updates of certificates periodically | ||
|
||
[Service] | ||
Type=oneshot | ||
EnvironmentFile=-{{ keyvault_certdeploy_config_root }}/.env | ||
ExecStart=/usr/local/sbin/keyvault-certdeploy sync -v |
13 changes: 13 additions & 0 deletions
13
.../ansible/roles/keyvault-certdeploy.common/templates/keyvault-certdeploy-periodic.timer.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# ++++++++++++++++++++++++++++++++++++++++++++ | ||
# DO NOT EDIT MANUALLY | ||
# ++++++++++++++++++++++++++++++++++++++++++++ | ||
# {{ ansible_managed }} | ||
[Unit] | ||
Description=Periodically check for certificate updates | ||
|
||
[Timer] | ||
OnBootSec=1d | ||
OnUnitActiveSec=1d | ||
|
||
[Install] | ||
WantedBy=timers.target |
16 changes: 16 additions & 0 deletions
16
examples/ansible/roles/keyvault-certdeploy.common/templates/keyvault-certdeploy.service.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# ++++++++++++++++++++++++++++++++++++++++++++ | ||
# DO NOT EDIT MANUALLY | ||
# ++++++++++++++++++++++++++++++++++++++++++++ | ||
# {{ ansible_managed }} | ||
[Unit] | ||
Description=Fetch updates of certificates on boot | ||
After=systemd-networkd-wait-online.service | ||
Before=network-online.target | ||
|
||
[Service] | ||
Type=oneshot | ||
EnvironmentFile=-{{ keyvault_certdeploy_config_root }}/.env | ||
ExecStart=/usr/local/sbin/keyvault-certdeploy sync -v --nohooks | ||
|
||
[Install] | ||
WantedBy=network-online.target |
8 changes: 8 additions & 0 deletions
8
examples/ansible/roles/keyvault-certdeploy.common/templates/vault.yml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# ++++++++++++++++++++++++++++++++++++++++++++ | ||
# DO NOT EDIT MANUALLY | ||
# ++++++++++++++++++++++++++++++++++++++++++++ | ||
# {{ ansible_managed }} | ||
keyvault: | ||
name: {{ keyvault_certdeploy_vault_name }} | ||
url: {{ keyvault_certdeploy_vault_url }} | ||
certs: |
9 changes: 9 additions & 0 deletions
9
examples/ansible/roles/keyvault-certdeploy.common/vars/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
keyvault_certdeploy_version: 1.0.0-beta4 | ||
keyvault_certdeploy_url: "https://github.com/emgag/keyvault-certdeploy/releases/download/v{{ keyvault_certdeploy_version }}/keyvault-certdeploy_{{ keyvault_certdeploy_version }}_linux_amd64.tar.gz" | ||
keyvault_certdeploy_checksum: "sha256:936bd700a968086142ff40cd403e165d6c6ff3f15309a9a37b7008e2454ac580" | ||
|
||
keyvault_certdeploy_config_root: /etc/keyvault-certdeploy | ||
keyvault_certdeploy_config: "{{ keyvault_certdeploy_config_root }}/keyvault-certdeploy.yml" | ||
keyvault_certdeploy_configd: "{{ keyvault_certdeploy_config_root }}/conf.d" | ||
keyvault_certdeploy_hooksd: "{{ keyvault_certdeploy_config_root }}/hooks.d" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[Unit] | ||
Description=Fetch updates of certificates periodically | ||
|
||
[Service] | ||
Type=oneshot | ||
EnvironmentFile=-/etc/keyvault-certdeploy/.env | ||
ExecStart=/usr/local/sbin/keyvault-certdeploy sync -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Unit] | ||
Description=Periodically check for certificate updates | ||
|
||
[Timer] | ||
OnBootSec=1d | ||
OnUnitActiveSec=1d | ||
|
||
[Install] | ||
WantedBy=timers.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=Fetch updates of certificates on boot | ||
After=systemd-networkd-wait-online.service | ||
Before=network-online.target | ||
|
||
[Service] | ||
Type=oneshot | ||
EnvironmentFile=-/etc/keyvault-certdeploy/.env | ||
ExecStart=/usr/local/sbin/keyvault-certdeploy sync -v --nohooks | ||
|
||
[Install] | ||
WantedBy=network-online.target |