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

Add ansible playbooks #22

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions provisioning/ansible/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# ansible

```
ansible-playbook -c local -i local, site.yml
```
12 changes: 12 additions & 0 deletions provisioning/ansible/roles/common/files/isulibrary.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Isulibrary

[Service]
Type=simple
ExecStart=/snap/bin/go run main.go
WorkingDirectory=/home/isucon/webapp/go
User=isucon
Group=isucon

[Install]
WantedBy=multi-user.target
1 change: 1 addition & 0 deletions provisioning/ansible/roles/common/files/sudoers_isucon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
isucon ALL=(ALL) NOPASSWD: ALL
88 changes: 88 additions & 0 deletions provisioning/ansible/roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
- ansible.builtin.package:
name:
- git
- make
- mysql-server
- qrencode
- sudo
state: present

- community.general.snap:
name: go
classic: true

- ansible.builtin.user:
name: isucon
shell: /bin/bash

- ansible.builtin.copy:
src: sudoers_isucon
dest: /etc/sudoers.d/isucon
validate: /usr/sbin/visudo -csf %s

- ansible.builtin.package:
name: mysql-server
state: present

- ansible.builtin.service:
name: mysql
enabled: true
state: started

- ansible.builtin.shell: |
mysql -e "CREATE DATABASE IF NOT EXISTS isulibrary"
mysql -e "CREATE USER IF NOT EXISTS isucon@localhost IDENTIFIED BY 'isucon'"
mysql -e "GRANT ALL ON isulibrary.* TO isucon@localhost"

- ansible.builtin.git:
repo: "https://github.com/logica0419/gasshuku-isucon.git"
dest: /tmp/gasshuku-isucon

- ansible.builtin.get_url:
url: https://github.com/logica0419/gasshuku-isucon/releases/download/initial-data/1_data.sql
dest: /tmp/gasshuku-isucon/webapp/sql/1_data.sql

- ansible.builtin.file:
path: /tmp/gasshuku-isucon/webapp/sql/init_db.sh
mode: a+x

- ansible.builtin.shell: /tmp/gasshuku-isucon/webapp/sql/init_db.sh

- ansible.builtin.get_url:
url: https://github.com/logica0419/gasshuku-isucon/releases/download/initial-data/init_data.json
dest: /tmp/gasshuku-isucon/bench/repository/init_data.json

- ansible.builtin.shell: |
/snap/bin/go build -o bench main.go
args:
chdir: /tmp/gasshuku-isucon/bench

- ansible.builtin.copy:
src: "/tmp/gasshuku-isucon/{{ item }}"
dest: "/home/isucon/{{ item }}"
owner: isucon
group: isucon
mode: preserve
loop:
- Makefile
- README.md
- bench/
- webapp/

- ansible.builtin.file:
path: /tmp/gasshuku-isucon
state: absent

- ansible.builtin.copy:
src: "{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
loop:
- isulibrary.service

- ansible.builtin.systemd:
daemon_reload: true

- ansible.builtin.service:
name: isulibrary
enabled: true
state: started
5 changes: 5 additions & 0 deletions provisioning/ansible/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: all
become: yes
roles:
- common