Skip to content

Commit 9ed0455

Browse files
committed
add ansible/lint
1 parent 27e8eee commit 9ed0455

File tree

4 files changed

+46
-31
lines changed

4 files changed

+46
-31
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CI_RUN=cd intbot && DJANGO_SETTINGS_MODULE="intbot.settings" DJANGO_ENV="ci"
1515

1616
# Deployment
1717
DEPLOY_CMD=cd deploy && uvx --from "ansible-core" ansible-playbook -i hosts.yml
18+
DEPLOY_LINT_CMD=cd deploy && uvx --from "ansible-lint" ansible-lint
1819

1920
# mostly useful for docker and deployment
2021
current_git_hash=$(shell git rev-parse HEAD)
@@ -149,3 +150,8 @@ deploy/provision:
149150
deploy/app:
150151
@echo "Deploying version $(V) to a remote server"
151152
$(DEPLOY_CMD) playbooks/03_app.yml --extra-vars "app_version=$(V)"
153+
154+
deploy/lint:
155+
$(DEPLOY_LINT_CMD) playbooks/01_setup.yml
156+
$(DEPLOY_LINT_CMD) playbooks/02_nginx.yml
157+
$(DEPLOY_LINT_CMD) playbooks/03_app.yml

deploy/playbooks/01_setup.yml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
- name: Deploy nginx and Let's Encrypt SSL certificate
22
hosts: intbot_setup
3-
become: yes
4-
gather_facts: yes
3+
become: true
4+
gather_facts: true
55

66
tasks:
77
- name: Install Docker dependencies
8-
apt:
8+
ansible.builtin.apt:
99
name: "{{ package }}"
1010
state: present
11-
update_cache: yes
11+
update_cache: true
1212
vars:
1313
package:
1414
- apt-transport-https
@@ -21,22 +21,22 @@
2121
- name: Install Docker
2222
block:
2323
- name: Add Docker GPG key
24-
apt_key:
24+
ansible.builtin.apt_key:
2525
url: https://download.docker.com/linux/ubuntu/gpg
2626
state: present
2727

2828
- name: Add Docker repository
29-
apt_repository:
29+
ansible.builtin.apt_repository:
3030
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable
3131
state: present
3232

3333
- name: Install Docker
34-
apt:
34+
ansible.builtin.apt:
3535
name: docker-ce
3636
state: present
3737

3838
- name: Combine non-root users to a single list
39-
set_fact:
39+
ansible.builtin.set_fact:
4040
non_root_user_names: ["{{ nginx_user }}", "{{ app_user }}"]
4141

4242
- name: Create non-root users
@@ -45,10 +45,10 @@
4545
ansible.builtin.user:
4646
name: "{{ username }}"
4747
shell: "/bin/bash"
48-
generate_ssh_key: yes
48+
generate_ssh_key: true
4949
ssh_key_type: ed25519
5050
ssh_key_comment: "{{ username }}@{{ inventory_hostname }}"
51-
create_home: yes
51+
create_home: true
5252
loop: "{{ non_root_user_names }}"
5353
loop_control:
5454
loop_var: username
@@ -59,37 +59,37 @@
5959
state: directory
6060
owner: "{{ username }}"
6161
group: "{{ username }}"
62+
mode: "0755"
6263
loop: "{{ non_root_user_names }}"
6364
loop_control:
6465
loop_var: username
6566

6667
- name: Then copy the authorized_keys from root so you can ssh later to the user
67-
copy:
68+
ansible.builtin.copy:
6869
src: "/root/.ssh/authorized_keys"
6970
dest: "/home/{{ username }}/.ssh/authorized_keys"
7071
owner: "{{ username }}"
7172
group: "{{ username }}"
7273
mode: "0600"
73-
remote_src: "yes"
74+
remote_src: true
7475
loop: "{{ non_root_user_names }}"
7576
loop_control:
7677
loop_var: username
7778

7879
- name: Add the non root users (both nginx and app) to docker group
79-
user:
80+
ansible.builtin.user:
8081
name: "{{ username }}"
8182
groups: docker
82-
append: yes
83+
append: true
8384
loop: "{{ non_root_user_names }}"
8485
loop_control:
8586
loop_var: username
8687

8788
- name: Read the deploy public key
88-
slurp:
89+
ansible.builtin.slurp:
8990
src: "/home/{{ app_user }}/.ssh/id_ed25519.pub"
9091
register: deploy_key
9192

9293
- name: Display the public key
93-
debug:
94+
ansible.builtin.debug:
9495
msg: "For private repositories, make sure to put this key as deploy key on github: {{ deploy_key.content | b64decode }}"
95-

deploy/playbooks/02_nginx.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,28 @@
44
tasks:
55
- name: Copy nginx configuration file
66
ansible.builtin.template:
7-
src: ../templates/nginx/nginx.conf.j2
7+
src: nginx/nginx.conf.j2
88
dest: ./nginx.conf
9+
mode: "0644"
910

1011
- name: Create a server Makefile (for nginx) to manage on-server tasks
1112
ansible.builtin.template:
12-
src: ../templates/nginx/Makefile.nginx.j2
13+
src: nginx/Makefile.nginx.j2
1314
dest: ./Makefile
15+
mode: "0644"
1416

1517
- name: Set up docker-compose.yml on the remote server
1618
ansible.builtin.template:
17-
src: ../templates/nginx/docker-compose.nginx.yml.j2
19+
src: nginx/docker-compose.nginx.yml.j2
1820
dest: ./docker-compose.yml
21+
mode: "0644"
1922

2023
- name: Make sure the directory structure for certs exist
21-
shell: mkdir -p ./data/certbot/conf
24+
ansible.builtin.file:
25+
path: "/home/{{ ansible_user }}/data/cerbot/conf"
26+
state: directory
27+
mode: "0755"
2228

2329
- name: Display info at the end
24-
debug:
30+
ansible.builtin.debug:
2531
msg: "Go to /home/{{ ansible_user }} and run make certbot/init-staging; then make certbot/upgrade-to-prod"

deploy/playbooks/03_app.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@
33

44
tasks:
55
- name: Clone the repository to a specific version (to a temp location)
6-
git:
6+
ansible.builtin.git:
77
repo: "{{ repository_url }}"
88
dest: /tmp/src
9-
accept_hostkey: yes
9+
accept_hostkey: true
1010
version: "{{ app_version }}"
1111

1212
- name: Build with a given commit hash
1313
# This will be stored in local registry, and available as version to docker-compose
1414
# where we can just reference correct version
15-
shell: "cd /tmp/src && make docker/build V={{ app_version }}"
15+
ansible.builtin.shell: "cd /tmp/src && make docker/build V={{ app_version }}"
1616

1717
- name: Create a server Makefile to manage app tasks
1818
ansible.builtin.template:
19-
src: ../templates/app/Makefile.app.j2
19+
src: app/Makefile.app.j2
2020
dest: ./Makefile
21+
mode: "0644"
2122

2223
- name: Set up docker-compose.yml for the app
2324
ansible.builtin.template:
24-
src: ../templates/app/docker-compose.app.yml.j2
25+
src: app/docker-compose.app.yml.j2
2526
dest: ./docker-compose.yml
27+
mode: "0644"
2628

2729
- name: Check if the env file exists
2830
ansible.builtin.stat:
@@ -31,8 +33,9 @@
3133

3234
- name: If env file doesn't exist - copy the example
3335
ansible.builtin.copy:
34-
src: ../templates/app/intbot.env.example
36+
src: app/intbot.env.example
3537
dest: intbot.env.example
38+
mode: "0644"
3639
when: not env_file.stat.exists
3740

3841
- name: If the env file doesn't exist - fail with error message
@@ -41,10 +44,10 @@
4144
when: not env_file.stat.exists
4245

4346
- name: Start docker compose to see if everything is running
44-
shell: "docker compose up -d"
47+
ansible.builtin.shell: "docker compose up -d"
4548

4649
- name: Migrate on prod
47-
shell: "make prod/migrate"
50+
ansible.builtin.shell: "make prod/migrate"
4851

4952
- name: Restart everything and finish
50-
shell: "docker compose up -d"
53+
ansible.builtin.shell: "docker compose up -d"

0 commit comments

Comments
 (0)