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

ansible: add cloudflare-deploy role #3501

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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" }