-
Notifications
You must be signed in to change notification settings - Fork 1
/
playbook.yaml
167 lines (146 loc) · 4.73 KB
/
playbook.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
---
- hosts: 127.0.0.1
vars:
ansible_python_interpreter: /usr/bin/python3
vars_files:
- vars/main.yaml
tasks:
- name: Download step binaries for {{ arch }}
get_url:
url: "{{ item.url }}"
dest: "{{ tmp }}/{{ item.dest }}"
with_items:
- { url: "{{ smallstep_url }}/cli/releases/download/v{{ step_version }}/{{ step_file }}", dest: "{{ step_file }}" }
- { url: "{{ smallstep_url }}/certificates/releases/download/v{{ stepca_version }}/{{ stepca_file }}", dest: "{{ stepca_file }}" }
- name: Extract archives
unarchive:
src: "{{ tmp }}/{{ item }}"
dest: "{{ tmp }}/"
with_items:
- "{{ step_file }}"
- "{{ stepca_file }}"
- name: Make sure {{ usr_local }}/bin exists
file:
path: "{{ usr_local }}"
state: directory
- name: Copy binaries to {{ usr_local }}/bin/
copy:
src: "{{ item }}"
dest: "{{ usr_local }}/bin/"
mode: '0755'
with_items:
- "{{ tmp }}/step_{{ step_version }}/bin/step"
- "{{ tmp }}/step-certificates_{{ stepca_version }}/bin/step-ca"
- "{{ tmp }}/step-certificates_{{ stepca_version }}/bin/step-awskms-init"
- "{{ tmp }}/step-certificates_{{ stepca_version }}/bin/step-cloudkms-init"
become: yes
- name: Install list of required packages
package: name={{ item }} state=present
become: yes
with_items:
- build-essential
- git
- tmux
- jq
- name: Check for {{ dot_step }}
stat:
path: "{{ dot_step }}"
register: dot_step_result
- name: Move {{ dot_step }} if it already exists
debug:
msg: "Aborting as {{ dot_step }} already exists. Please move/delete first as otherwise 'step ca init' will hang."
failed_when: dot_step_result.stat.exists
- name: step ca init
command:
cmd: step ca init --name {{ ca_name }} --dns {{ ca_dns }} --address {{ ca_address }} --provisioner "{{ ca_provisioner }}" --password-file "./files/{{ key_password_file }}" --provisioner-password-file "./files/{{ provisioner_password_file }}"
creates: "{{ ca_json }}"
register: stepca_output
- name: Display step ca init output
debug:
msg: "{{ item }}"
verbosity: 2
with_items:
- "{{ stepca_output.stdout_lines }}"
- "{{ stepca_output.stderr_lines }}"
when: stepca_output.stdout_lines is defined and stepca_output.stderr_lines is defined
# 32 bit, e.g. ARMv7, needs BadgerV2
- name: Use BadgerV2 instead of Badger
lineinfile:
path: "{{ ca_json }}"
regexp: '^(\s+)"type":\s+"badger",'
line: '\1"type": "badgerv2",'
backrefs: yes
# Only add below block once
- name: Check if default durations already set
command: jq -e '.authority.provisioners[] | .claims' "{{ ca_json }}"
ignore_errors: yes
check_mode: no
changed_when: no
register: hasClaimsAlready
- name: Debug2
debug:
var: hasClaimsAlready.rc
verbosity: 1
- name: Set Default JWK parameters, like default life time of a certificate
blockinfile:
path: "{{ ca_json }}"
insertafter: '"type":\s"JWK",'
marker: ""
block: |1
"claims": {
"minTLSCertDuration": "5m",
"maxTLSCertDuration": "720h",
"defaultTLSCertDuration": "168h",
"disableRenewal": false,
"minHostSSHCertDuration": "5m",
"maxHostSSHCertDuration": "1680h",
"minUserSSHCertDuration": "5m",
"maxUserSSHCertDuration": "24h",
"enableSSHCA": true
},
when: hasClaimsAlready.rc != 0
- name: Create ~/.step/pass/
file:
path: "{{ pass_target_location }}"
state: directory
mode: '0700'
- name: Copy passphrase files to .step/
copy:
src: "{{ item }}"
dest: "{{ pass_target_location }}/"
mode: '0700'
with_items:
- "./files/{{ key_password_file }}"
- "./files/{{ provisioner_password_file }}"
- name: Debian or RedHat
shell: if [[ -d /etc/sysconfig ]] ; then echo "sysconfig" ; else echo "default" ; fi
register: etc_config
changed_when: false
- set_fact:
etc_config={{ etc_config.stdout }}
- name: Copy /etc/sysconfig/step-ca
template:
src: step-ca.j2
dest: /etc/{{ etc_config }}/step-ca
become: yes
- name: Copy systemd unit
template:
src: step-ca.service.j2
dest: /etc/systemd/system/step-ca.service
become: yes
notify: Start step CA
- name: Get root cert fingerprint
shell: step certificate fingerprint $(step path)/certs/root_ca.crt
register: fingerprint
changed_when: false
- name: Print fingerprint
debug:
var: fingerprint.stdout
handlers:
- name: Start step CA
systemd:
daemon_reload: yes
name: step-ca
enabled: yes
state: started
become: yes