Skip to content

Commit

Permalink
ansible: add cloudflare-deploy role
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Sep 27, 2023
1 parent e3059d7 commit c1f679d
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ansible/playbooks/jenkins/worker/create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,23 @@

environment: '{{remote_env}}'


- hosts:
- release
gather_facts: yes

roles:
- role: cloudflare-deploy
release_home_dir: "{{ home }}/{{ server_user }}"

pre_tasks:
- name: release check if secret is properly set
fail:
failed_when: not secret

environment: '{{remote_env}}'


#
# Set up Jenkins Workspace servers
#
Expand Down
1 change: 1 addition & 0 deletions ansible/roles/cloudflare-deploy/files/worker_config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[profile worker]
10 changes: 10 additions & 0 deletions ansible/roles/cloudflare-deploy/meta/argument_specs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

argument_specs:
main:
short_description: Set up specific to hosts that build releases.
options:
release_home_dir:
description: The user's HOME directory.
required: yes
type: str
6 changes: 6 additions & 0 deletions ansible/roles/cloudflare-deploy/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---

dependencies:
- role: read-secrets
- role: user-create
when: not os|startswith("win")
15 changes: 15 additions & 0 deletions ansible/roles/cloudflare-deploy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

# Set up release hosts to be able to upload to clouflare.
# Requires access to the secrets repository. User should have already
# been prompted for GPG credentials during the inventory load.

- name: run os-specific deploy
include: "{{ deploy_include }}"
loop_control:
loop_var: deploy_include
with_first_found:
- files:
- "{{ role_path }}/tasks/partials/{{ os|stripversion }}.yml"
- "{{ role_path }}/tasks/partials/default.yml"
skip: true
46 changes: 46 additions & 0 deletions ansible/roles/cloudflare-deploy/tasks/partials/default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---

- name: create .aws directory
ansible.builtin.file:
dest: "{{ release_home_dir }}/.aws"
owner: "{{ server_user }}"
group: "{{ server_user }}"
state: directory

- name: copy credentials to deploy release artifacts
ansible.builtin.copy:
content: "{{ secrets.worker_credentials }}"
dest: "{{ release_home_dir }}/.aws/credentials"
owner: "{{ server_user }}"
group: "{{ server_user }}"

- name: write worker_config
ansible.builtin.copy:
dest: "{{ release_home_dir }}/.aws/config"
src: "{{ role_path }}/files/worker_config"
owner: "{{ server_user }}"
group: "{{ server_user }}"
when: not os|startswith("win")


# https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html
- name: Download awscliv2 installer
unarchive:
src: "https://awscli.amazonaws.com/awscli-exe-linux-{{ ansible_architecture }}.zip"
dest: "/tmp"
remote_src: true
creates: '/tmp/aws'
mode: 0755

- name: Run awscliv2 installer
command:
args:
cmd: "/tmp/aws/install"
creates: /usr/local/bin/aws
become: true
register: aws_install

- name: "Show awscliv2 installer output"
debug:
var: aws_install
verbosity: 2
28 changes: 28 additions & 0 deletions ansible/roles/cloudflare-deploy/tasks/partials/macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

- name: create .aws directory
ansible.builtin.file:
dest: "{{ release_home_dir }}/.aws"
owner: "{{ server_user }}"
group: "{{ server_user }}"
state: directory

- name: copy credentials to deploy release artifacts
ansible.builtin.copy:
content: "{{ secrets.worker_credentials }}"
dest: "{{ release_home_dir }}/.aws/credentials"
owner: "{{ server_user }}"
group: "{{ server_user }}"

- name: write worker_config
ansible.builtin.copy:
dest: "{{ release_home_dir }}/.aws/config"
src: "{{ role_path }}/files/worker_config"
owner: "{{ server_user }}"
group: "{{ server_user }}"
when: not os|startswith("win")


- name: install awscli
community.general.homebrew: name="awscli" state=present
become_user: "{{ ansible_user }}"
19 changes: 19 additions & 0 deletions ansible/roles/cloudflare-deploy/tasks/partials/win.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---

- name: create .aws directory
win_file:
path: '{{ansible_facts["env"]["USERPROFILE"]}}\.aws'
state: directory

- name: copy credentials to deploy release artifacts
win_copy:
content: "{{ secrets.worker_credentials }}"
dest: '{{ansible_facts["env"]["USERPROFILE"]}}\.aws\credentials'

- name: write worker_config
win_copy:
dest: '{{ansible_facts["env"]["USERPROFILE"]}}\.aws\config'
src: "{{ role_path }}/files/worker_config"

- name: install AWS CLI
win_chocolatey: name=awscli
1 change: 1 addition & 0 deletions ansible/roles/read-secrets/tasks/partials/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
with_items:
- { 'key': 'staging_key', 'file': "staging_id_rsa_private.key" }
- { 'key': 'known_hosts', 'file': "known_hosts" }
- { 'key': 'worker_credentials', 'file': "release-cloudflare-worker-credentials" }

0 comments on commit c1f679d

Please sign in to comment.