Skip to content

Instantly share code, notes, and snippets.

@wate
Last active October 20, 2018 08:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wate/301bb4ba9e9c2752efc86237b3d386ba to your computer and use it in GitHub Desktop.
Save wate/301bb4ba9e9c2752efc86237b3d386ba to your computer and use it in GitHub Desktop.
Let's Scratch 3.0 GUI
[defaults]
hash_behaviour = merge
retry_files_enabled = False
#!/bin/sh
echo "# ----------------------------"
echo "# Install Ansible"
echo "# ----------------------------"
if [ ! -f /usr/bin/dirmngr ]; then
apt-get install -y dirmngr
fi
if [ ! -f /etc/apt/sources.list.d/ansible.list ]; then
echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main">/etc/apt/sources.list.d/ansible.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
apt-get update
fi
if [ ! -f /usr/bin/ansible ]; then
apt-get install -y ansible
fi
- name: Scratch GUIをデプロイする
hosts: all
vars:
# インストールするnode.jsのメジャーバージョン
nodejs_major_version: 10
# Scratch GUIの実行ユーザー
scratch_gui_user: scratch
# Scratch GUIの実行グループ
scratch_gui_group: scratch
# Scratch GUIの設置先
scratch_gui_dest: /opt/scratch-gui
handlers:
- name: Scratch GUIを再起動する
systemd:
name: scratch-gui
state: restarted
daemon_reload: yes
tasks:
- name: キャッシュおよびインストール済みパッケージを更新する
apt:
update_cache: yes
only_upgrade: yes
- name: aclをインストールする(Ansible用)
apt:
name: acl
- name: apt-transport-httpsをインストールする
apt:
name: apt-transport-https
- name: NodeSourceのGPGキーを追加する
apt_key:
url: https://deb.nodesource.com/gpgkey/nodesource.gpg.key
- name: NodeSourceのリポジトリを追加する
apt_repository:
repo: deb https://deb.nodesource.com/node_{{ nodejs_major_version }}.x {{ ansible_distribution_release }} main
filename: nodesource
- name: node.jsをインストールする
apt:
name: nodejs
default_release: "{{ ansible_distribution_release }}"
- name: Scratch GUI用のグループを追加する
group:
name: "{{ scratch_gui_group }}"
system: yes
- name: Scratch GUI用のユーザーを追加する
user:
name: "{{ scratch_gui_user }}"
system: yes
- name: gitをインストールする
apt:
name: git
- name: Scratch GUIのデプロイ先ディレクトリを作成する
file:
path: "{{ scratch_gui_dest }}"
owner: "{{ scratch_gui_user }}"
group: "{{ scratch_gui_group }}"
state: directory
- block:
- name: Scratch GUIをチェックアウトする
git:
repo: https://github.com/LLK/scratch-gui.git
dest: "{{ scratch_gui_dest }}"
version: master
depth: 1
- name: npmパッケージをインストールする
command: npm install
args:
chdir: "{{ scratch_gui_dest }}"
creates: "{{ scratch_gui_dest }}/package-lock.json"
become: yes
become_user: "{{ scratch_gui_user }}"
- name: systemdのユニットファイルを作成する
template:
src: scratch-gui.service.j2
dest: /lib/systemd/system/scratch-gui.service
notify: Scratch GUIを再起動する
- name: Scratch GUIサービスを起動し有効にする
systemd:
name: scratch-gui
state: started
enabled: yes
- name: デプロイ完了メッセージを表示する
debug:
msg: "Let's Scratch 3.0 GUI ( http://localhost:8601/ ) "
[Unit]
Description=Scratch GUI
After=network.target
[Service]
Type=simple
User={{ scratch_gui_user }}
Group={{ scratch_gui_group }}
WorkingDirectory={{ scratch_gui_dest }}
ExecStart=/usr/bin/npm start
Restart=on-failure
[Install]
WantedBy=multi-user.target
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "histudy/stretch"
config.vm.network "forwarded_port", guest: 8601, host: 8601
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
# Ansibleのインストール
config.vm.provision "shell", path: "install_ansible.sh"
# Scratch GUIをセットアップする
config.vm.provision "ansible_local" do |ansible|
ansible.become = true
ansible.compatibility_mode = "2.0"
ansible.playbook = "playbook.yml"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment