Skip to content

Commit c1f679d

Browse files
committed
ansible: add cloudflare-deploy role
1 parent e3059d7 commit c1f679d

File tree

9 files changed

+143
-0
lines changed

9 files changed

+143
-0
lines changed

ansible/playbooks/jenkins/worker/create.yml

+17
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@
5555

5656
environment: '{{remote_env}}'
5757

58+
59+
- hosts:
60+
- release
61+
gather_facts: yes
62+
63+
roles:
64+
- role: cloudflare-deploy
65+
release_home_dir: "{{ home }}/{{ server_user }}"
66+
67+
pre_tasks:
68+
- name: release check if secret is properly set
69+
fail:
70+
failed_when: not secret
71+
72+
environment: '{{remote_env}}'
73+
74+
5875
#
5976
# Set up Jenkins Workspace servers
6077
#
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[profile worker]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
3+
argument_specs:
4+
main:
5+
short_description: Set up specific to hosts that build releases.
6+
options:
7+
release_home_dir:
8+
description: The user's HOME directory.
9+
required: yes
10+
type: str
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
3+
dependencies:
4+
- role: read-secrets
5+
- role: user-create
6+
when: not os|startswith("win")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
3+
# Set up release hosts to be able to upload to clouflare.
4+
# Requires access to the secrets repository. User should have already
5+
# been prompted for GPG credentials during the inventory load.
6+
7+
- name: run os-specific deploy
8+
include: "{{ deploy_include }}"
9+
loop_control:
10+
loop_var: deploy_include
11+
with_first_found:
12+
- files:
13+
- "{{ role_path }}/tasks/partials/{{ os|stripversion }}.yml"
14+
- "{{ role_path }}/tasks/partials/default.yml"
15+
skip: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
3+
- name: create .aws directory
4+
ansible.builtin.file:
5+
dest: "{{ release_home_dir }}/.aws"
6+
owner: "{{ server_user }}"
7+
group: "{{ server_user }}"
8+
state: directory
9+
10+
- name: copy credentials to deploy release artifacts
11+
ansible.builtin.copy:
12+
content: "{{ secrets.worker_credentials }}"
13+
dest: "{{ release_home_dir }}/.aws/credentials"
14+
owner: "{{ server_user }}"
15+
group: "{{ server_user }}"
16+
17+
- name: write worker_config
18+
ansible.builtin.copy:
19+
dest: "{{ release_home_dir }}/.aws/config"
20+
src: "{{ role_path }}/files/worker_config"
21+
owner: "{{ server_user }}"
22+
group: "{{ server_user }}"
23+
when: not os|startswith("win")
24+
25+
26+
# https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
27+
- name: Download awscliv2 installer
28+
unarchive:
29+
src: "https://awscli.amazonaws.com/awscli-exe-linux-{{ ansible_architecture }}.zip"
30+
dest: "/tmp"
31+
remote_src: true
32+
creates: '/tmp/aws'
33+
mode: 0755
34+
35+
- name: Run awscliv2 installer
36+
command:
37+
args:
38+
cmd: "/tmp/aws/install"
39+
creates: /usr/local/bin/aws
40+
become: true
41+
register: aws_install
42+
43+
- name: "Show awscliv2 installer output"
44+
debug:
45+
var: aws_install
46+
verbosity: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
3+
- name: create .aws directory
4+
ansible.builtin.file:
5+
dest: "{{ release_home_dir }}/.aws"
6+
owner: "{{ server_user }}"
7+
group: "{{ server_user }}"
8+
state: directory
9+
10+
- name: copy credentials to deploy release artifacts
11+
ansible.builtin.copy:
12+
content: "{{ secrets.worker_credentials }}"
13+
dest: "{{ release_home_dir }}/.aws/credentials"
14+
owner: "{{ server_user }}"
15+
group: "{{ server_user }}"
16+
17+
- name: write worker_config
18+
ansible.builtin.copy:
19+
dest: "{{ release_home_dir }}/.aws/config"
20+
src: "{{ role_path }}/files/worker_config"
21+
owner: "{{ server_user }}"
22+
group: "{{ server_user }}"
23+
when: not os|startswith("win")
24+
25+
26+
- name: install awscli
27+
community.general.homebrew: name="awscli" state=present
28+
become_user: "{{ ansible_user }}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
3+
- name: create .aws directory
4+
win_file:
5+
path: '{{ansible_facts["env"]["USERPROFILE"]}}\.aws'
6+
state: directory
7+
8+
- name: copy credentials to deploy release artifacts
9+
win_copy:
10+
content: "{{ secrets.worker_credentials }}"
11+
dest: '{{ansible_facts["env"]["USERPROFILE"]}}\.aws\credentials'
12+
13+
- name: write worker_config
14+
win_copy:
15+
dest: '{{ansible_facts["env"]["USERPROFILE"]}}\.aws\config'
16+
src: "{{ role_path }}/files/worker_config"
17+
18+
- name: install AWS CLI
19+
win_chocolatey: name=awscli

ansible/roles/read-secrets/tasks/partials/release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
with_items:
1313
- { 'key': 'staging_key', 'file': "staging_id_rsa_private.key" }
1414
- { 'key': 'known_hosts', 'file': "known_hosts" }
15+
- { 'key': 'worker_credentials', 'file': "release-cloudflare-worker-credentials" }

0 commit comments

Comments
 (0)