Ansible のレシピを作ってみました.
背景
OctoPrint のインストール手順全体は下記にありますが比較的長いので,Ansible を使って自動化してみました.
対象とする Ubuntu のバージョンは,Ubuntu 20.04 です.

Setting up OctoPrint on a Raspberry Pi running Raspbian or Raspberry Pi OS
This is a wiki node that every user of this forum at trust level 1 or higher can edit. Find problems, typos, or incorrect information? Please contribute. ☝ He...
リポジトリ
レシピ全体は下記に置いてあります.
GitHub - kimata/raspberry_config: Raspberry Pi を Ansible でセットアップするスクリプト
Raspberry Pi を Ansible でセットアップするスクリプト. Contribute to kimata/raspberry_config development by creating an account on GitHub.
上記をチェックアウト後,下記のコマンドを実行することで,OctoPrint および MJPG-Streamer のインストールが行われます.
1 |
ansible-playbook -k -i ホスト名, octoprint.yml |
レシピ
レシピの主要部分は下記となります. libjpeg-turbo8-dev の部分は,Ubuntu 20.04 以外の場合は修正が必要かもしれません.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
- name: Install packages apt: pkg: [ 'python3-pip', 'python3-dev', 'python3-setuptools', 'python3-venv', 'git', 'libyaml-dev', 'build-essential', 'haproxy', 'subversion', 'libjpeg-turbo8-dev', 'imagemagick', 'ffmpeg', 'libv4l-dev', 'cmake' ] update_cache: yes cache_valid_time: 86400 - name: Make direcrory file: path: '/home/ubuntu/{{item}}' state: directory mode: 0755 with_items: - OctoPrint - scripts become: no - name: Initialize venv shell: python3 -m venv venv args: chdir: /home/ubuntu/OctoPrint become: no - name: Install OctoPrint pip: name: octoprint virtualenv: /home/ubuntu/OctoPrint/venv become: no - name: Join group user: name: ubuntu groups: tty, dialout append: yes - name: Install service get_url: url: https://github.com/OctoPrint/OctoPrint/raw/master/scripts/octoprint.service dest: /etc/systemd/system/octoprint.service - name: Edit service lineinfile: dest: /etc/systemd/system/octoprint.service regexp: '{{item.regexp}}' line: '{{item.line}}' with_items: - regexp: ExecStart=/home/pi/OctoPrint/venv/bin/octoprint line: ExecStart=/home/ubuntu/OctoPrint/venv/bin/octoprint - regexp: User=pi line: User=ubuntu notify: restart octoprint - name: Edit config lineinfile: dest: /home/ubuntu/.octoprint/config.yaml regexp: host line: 'host: 127.0.0.1' insertafter: EOF become: no - name: Setting HAProxy template: src: haproxy/haproxy.cfg.j2 dest: /etc/haproxy/haproxy.cfg owner: root group: root mode: 0440 notify: restart haproxy - name: Checkout mjpg-streamer git: repo: https://github.com/jacksonliam/mjpg-streamer.git dest: /home/ubuntu/mjpg-streamer become: no - name: Build mjpg-streamer shell: make args: chdir: /home/ubuntu/mjpg-streamer/mjpg-streamer-experimental become: no - name: Install daemon script template: src: mjpg_streamer/webcamDaemon.j2 dest: /home/ubuntu/scripts/webcamDaemon mode: 0755 become: no - name: Install service template: src: mjpg_streamer/webcamd.service.j2 dest: /etc/systemd/system/webcamd.service notify: restart webcamd - name: Enable service systemd: name: '{{item}}' enabled: yes with_items: - octoprint - webcamd |
コメント