diff --git a/host_vars/cannelloni.binary.kitchen b/host_vars/cannelloni.binary.kitchen new file mode 100644 index 0000000..b3ce16a --- /dev/null +++ b/host_vars/cannelloni.binary.kitchen @@ -0,0 +1,61 @@ +mainsail_domain: cannelloni.binary.kitchen + +octoprint_groups: +- klipper +- tty + +octoprint_config_display_name: Voron 2.4 +octoprint_domain: cannelloni.binary.kitchen +octoprint_config_default_profile: _voron_2_4 +octoprint_has_webcam: false + +octoprint_additional_plugins: +- "https://github.com/thelastWallE/OctoprintKlipperPlugin/archive/master.zip" + +octoprint_config: + plugins: + klipper: + configuration: + config_path: /etc/klipper/ + confirm_reload: false + serial: + disconnectOnErrors: false + port: /home/klipper/printer + additionalPorts: + - /home/klipper/printer + + +octoprint_printer_profiles: +- axes: + e: + inverted: false + speed: 300 + x: + inverted: false + speed: 6000 + y: + inverted: false + speed: 6000 + z: + inverted: false + speed: 200 + color: default + extruder: + count: 1 + nozzleDiameter: 0.4 + offsets: + - - 0.0 + - 0.0 + sharedNozzle: false + heatedBed: true + heatedChamber: false + id: _voron_2_4 + model: Voron 2.4 + name: Voron 2.4 + volume: + custom_box: false + depth: 350.0 + formFactor: rectangular + height: 320.0 + origin: lowerleft + width: 350.0 \ No newline at end of file diff --git a/host_vars/canneloni.binary.kitchen b/host_vars/canneloni.binary.kitchen deleted file mode 100644 index 44bde5a..0000000 --- a/host_vars/canneloni.binary.kitchen +++ /dev/null @@ -1,45 +0,0 @@ -octoprint_display_name: Prusa Mini -octoprint_domain: canneloni.binary.kitchen - -octoprint_config_default_profile: _mini - -octoprint_printer_profiles: -- axes: - e: - inverted: false - speed: 300 - x: - inverted: false - speed: 6000 - y: - inverted: false - speed: 6000 - z: - inverted: false - speed: 200 - color: default - extruder: - count: 1 - nozzleDiameter: 0.4 - offsets: - - - 0.0 - - 0.0 - sharedNozzle: false - heatedBed: true - heatedChamber: false - id: _mini - model: Prusa Mini - name: Pursa Mini - volume: - custom_box: - x_min: 0 - x_max: 180 - y_min: -3 - y_max: 180 - z_min: 0 - z_max: 180 - depth: 180.0 - formFactor: rectangular - height: 180.0 - origin: lowerleft - width: 180 \ No newline at end of file diff --git a/host_vars/maccaroni.binary.kitchen b/host_vars/maccaroni.binary.kitchen index 84daeb3..f2bf931 100644 --- a/host_vars/maccaroni.binary.kitchen +++ b/host_vars/maccaroni.binary.kitchen @@ -1,7 +1,16 @@ -octoprint_display_name: Voron 2.4 +octoprint_config_display_name: Prusa Mini octoprint_domain: maccaroni.binary.kitchen +octoprint_config_default_profile: _mini -octoprint_config_default_profile: _voron_2_4 +octoprint_has_webcam: true +octoprint_ustreamer_args: "-r 1280x720" + +octoprint_config: + webcam: + ffmpeg: "/usr/bin/ffmpeg" + snapshot: "http://{{ octoprint_domain }}/webcam/snapshot" + stream: "http://{{ octoprint_domain }}/webcam/stream" + watermark: false octoprint_printer_profiles: - axes: @@ -27,13 +36,19 @@ octoprint_printer_profiles: sharedNozzle: false heatedBed: true heatedChamber: false - id: _voron_2_4 - model: Voron 2.4 - name: Voron 2.4 + id: _mini + model: Prusa Mini + name: Pursa Mini volume: - custom_box: false - depth: 350.0 + custom_box: + x_min: 0 + x_max: 180 + y_min: -3 + y_max: 180 + z_min: 0 + z_max: 180 + depth: 180.0 formFactor: rectangular - height: 320.0 + height: 180.0 origin: lowerleft - width: 350.0 \ No newline at end of file + width: 180 \ No newline at end of file diff --git a/host_vars/noodlehub.binary.kitchen b/host_vars/noodlehub.binary.kitchen new file mode 100644 index 0000000..2452a54 --- /dev/null +++ b/host_vars/noodlehub.binary.kitchen @@ -0,0 +1 @@ +noodlehub_domain: noodlehub.binary.kitchen \ No newline at end of file diff --git a/host_vars/raspberrypi b/host_vars/raspberrypi deleted file mode 100644 index 44d2eb3..0000000 --- a/host_vars/raspberrypi +++ /dev/null @@ -1,70 +0,0 @@ -octoprint_domain: raspberrypi.fritz.box -octoprint_config_default_profile: _mk3_single - -octoprint_printer_profiles: -- axes: - e: - inverted: false - speed: 300 - x: - inverted: false - speed: 6000 - y: - inverted: false - speed: 6000 - z: - inverted: false - speed: 200 - color: default - extruder: - count: 1 - nozzleDiameter: 0.4 - offsets: - - - 0.0 - - 0.0 - sharedNozzle: false - heatedBed: true - heatedChamber: false - id: _mk3_single - model: Prusa i3 Mk3s - name: Prusa i3 Mk3s - volume: - custom_box: false - depth: 200.0 - formFactor: rectangular - height: 200.0 - origin: lowerleft - width: 200.0 -- axes: - e: - inverted: false - speed: 300 - x: - inverted: false - speed: 6000 - y: - inverted: false - speed: 6000 - z: - inverted: false - speed: 200 - color: default - extruder: - count: 5 - nozzleDiameter: 0.4 - offsets: - - - 0.0 - - 0.0 - sharedNozzle: true - heatedBed: true - heatedChamber: false - id: _mk3_mmu - model: Prusa i3 Mk3s - name: Pursa i3 Mk3s with MMU - volume: - custom_box: false - depth: 200.0 - formFactor: rectangular - height: 200.0 - origin: lowerleft - width: 200.0 \ No newline at end of file diff --git a/host_vars/spaghetti.binary.kitchen b/host_vars/spaghetti.binary.kitchen index 57593f5..59ded83 100644 --- a/host_vars/spaghetti.binary.kitchen +++ b/host_vars/spaghetti.binary.kitchen @@ -1,7 +1,16 @@ -octoprint_display_name: Prusa MK3s +octoprint_config_display_name: Prusa MK3s octoprint_domain: spaghetti.binary.kitchen - octoprint_config_default_profile: _mk3_single +octoprint_has_webcam: true +octoprint_ustreamer_args: "-r 1280x720" + +octoprint_config: + webcam: + ffmpeg: "/usr/bin/ffmpeg" + snapshot: "http://{{ octoprint_domain }}/webcam/snapshot" + stream: "http://{{ octoprint_domain }}/webcam/stream" + watermark: false + octoprint_printer_profiles: - axes: diff --git a/hosts b/hosts index 65e9b2f..87b2f08 100644 --- a/hosts +++ b/hosts @@ -1,8 +1,13 @@ -[3D_Printers_test] -raspberrypi +noodlehub.binary.kitchen + +[3D_Printers] +spaghetti.binary.kitchen +maccaroni.binary.kitchen +#canneloni.binary.kitchen + [Octoprint_hosts] spaghetti.binary.kitchen maccaroni.binary.kitchen -canneloni.binary.kitchen +cannelloni.binary.kitchen diff --git a/roles/nginx/templates/nginx.conf.j2 b/roles/nginx/templates/nginx.conf.j2 index 2e1953c..8aed3a7 100644 --- a/roles/nginx/templates/nginx.conf.j2 +++ b/roles/nginx/templates/nginx.conf.j2 @@ -21,7 +21,7 @@ http { types_hash_max_size 2048; server_tokens off; - # server_names_hash_bucket_size 64; + server_names_hash_bucket_size 64; # server_name_in_redirect off; include /etc/nginx/mime.types; diff --git a/roles/octoprint/defaults/main.yml b/roles/octoprint/defaults/main.yml index 8b7d35f..1351fa9 100644 --- a/roles/octoprint/defaults/main.yml +++ b/roles/octoprint/defaults/main.yml @@ -1,7 +1,12 @@ octoprint_user: octoprint octoprint_group: octoprint octoprint_dir: "/opt/octoprint" +octoprint_conf_dir: "/home/{{ octoprint_user }}" octoprint_ssl: false +octoprint_has_webcam: false + +octoprint_default_plugins: + - "https://github.com/OctoPrint/OctoPrint-MQTT/archive/master.zip" octoprint_config_salt: "{{ octoprint_salt }}" octoprint_config_api_key: "{{ octoprint_api_key}}" diff --git a/roles/octoprint/files/_default.profile b/roles/octoprint/files/_default.profile deleted file mode 100644 index 2cbfc7f..0000000 --- a/roles/octoprint/files/_default.profile +++ /dev/null @@ -1,33 +0,0 @@ -axes: - e: - inverted: false - speed: 300 - x: - inverted: false - speed: 6000 - y: - inverted: false - speed: 6000 - z: - inverted: false - speed: 200 -color: default -extruder: - count: 1 - nozzleDiameter: 0.4 - offsets: - - - 0.0 - - 0.0 - sharedNozzle: false -heatedBed: true -heatedChamber: false -id: _default -model: Generic RepRap Printer -name: Default -volume: - custom_box: false - depth: 200.0 - formFactor: rectangular - height: 200.0 - origin: lowerleft - width: 200.0 diff --git a/roles/octoprint/files/users.yaml b/roles/octoprint/files/users.yaml deleted file mode 100644 index eb3c63c..0000000 --- a/roles/octoprint/files/users.yaml +++ /dev/null @@ -1,12 +0,0 @@ -binarykitchen: - active: true - apikey: null - groups: - - users - - admins - password: fb5adb1fbecb856f2f37da607ea17faf4887cb353b0d28459b12fb814b59d325825b7856d604efddf30b7b0a08e95af0b5a78d6912830bac171d84fe0d8d2a33 - permissions: [] - roles: - - user - - admin - settings: {} diff --git a/roles/octoprint/handlers/main.yml b/roles/octoprint/handlers/main.yml index 363256b..ec851c8 100644 --- a/roles/octoprint/handlers/main.yml +++ b/roles/octoprint/handlers/main.yml @@ -5,4 +5,7 @@ service: name=octoprint state=restarted - name: Restart nginx - service: name=nginx state=restarted \ No newline at end of file + service: name=nginx state=restarted + +- name: Restart ustreamer + service: name=ustreamer state=restarted \ No newline at end of file diff --git a/roles/octoprint/tasks/main.yml b/roles/octoprint/tasks/main.yml index 697c058..4c1d624 100644 --- a/roles/octoprint/tasks/main.yml +++ b/roles/octoprint/tasks/main.yml @@ -12,6 +12,14 @@ append: yes groups: - video + - dialout + +- name: Add octoprint user to additional groups + user: + name: "{{ octoprint_user }}" + append: yes + groups: "{{ octoprint_groups }}" + when: octoprint_groups is defined - name: Install requirements apt: @@ -19,10 +27,38 @@ - python3-pip - python3-virtualenv +- name: Create octoprint directory + file: + path: "{{ octoprint_dir }}" + state: directory + owner: "{{ octoprint_user }}" + group: "{{ octoprint_group }}" + - name: Create virtual env and install python dependencies pip: name: octoprint virtualenv: "{{ octoprint_dir }}" + become: true + become_user: "{{ octoprint_user }}" + +- name: Install default octoprint plugins + pip: + name: "{{ item }}" + virtualenv: "{{ octoprint_dir }}" + become: true + become_user: "{{ octoprint_user }}" + with_items: "{{ octoprint_default_plugins }}" + notify: Restart octoprint + +- name: Install additional octoprint plugins + pip: + name: "{{ item }}" + virtualenv: "{{ octoprint_dir }}" + become: true + become_user: "{{ octoprint_user }}" + with_items: "{{ octoprint_additional_plugins }}" + when: octoprint_additional_plugins is defined + notify: Restart octoprint - name: Create configuration directories file: @@ -34,6 +70,8 @@ with_items: - .octoprint - .octoprint/printerProfiles + - .octoprint/data + - .octoprint/data/appkeys - name: Install systemd unit template: src=octoprint.service.j2 dest=/lib/systemd/system/octoprint.service @@ -59,28 +97,39 @@ octoprint_config_combined: "{{ octoprint_default_config | combine(octoprint_config, recursive=True)}}" when: octoprint_config is defined -- name: Initial configuration of octoprint - copy: - content: "{{ octoprint_config_combined | to_nice_yaml }}" - dest: "/home/{{ octoprint_user }}/.octoprint/config.yaml" - when: not octoprint_register_config_stat.stat.exists +- name: Apply user config + set_fact: + octoprint_config_combined: "{{ octoprint_default_config }}" + when: octoprint_config is not defined -- name: Update existing Octoprint configuration + +- name: Configure Octoprint block: - - name: Read Octoprint config file - slurp: - src: "/home/{{ octoprint_user }}/.octoprint/config.yaml" - register: octoprint_register_config - - - name: Parse Octoprint config file - set_fact: - current_octoprint_config: "{{ octoprint_register_config['content'] | b64decode | from_yaml}}" - - - name: Write updated octoprint configuration + - name: Initial configuration of octoprint copy: - content: "{{ current_octoprint_config | combine(octoprint_config_combined, recursive=True) | to_nice_yaml}}" - dest: "/home/{{octoprint_user}}/.octoprint/config.yaml" - notify: Restart octoprint + content: "{{ octoprint_config_combined | to_nice_yaml }}" + dest: "/home/{{ octoprint_user }}/.octoprint/config.yaml" + when: not octoprint_register_config_stat.stat.exists + + - name: Update existing Octoprint configuration + block: + - name: Read Octoprint config file + slurp: + src: "/home/{{ octoprint_user }}/.octoprint/config.yaml" + register: octoprint_register_config + + - name: Parse Octoprint config file + set_fact: + current_octoprint_config: "{{ octoprint_register_config['content'] | b64decode | from_yaml}}" + + - name: Write updated octoprint configuration + copy: + content: "{{ current_octoprint_config | combine(octoprint_config_combined, recursive=True) | to_nice_yaml}}" + dest: "/home/{{octoprint_user}}/.octoprint/config.yaml" + notify: Restart octoprint + when: octoprint_register_config_stat.stat.exists + become: true + become_user: "{{ octoprint_user }}" ################################################################################ # Octoprint printer configuration @@ -91,48 +140,110 @@ content: "{{ item | to_nice_yaml}}" dest: "/home/{{ octoprint_user }}/.octoprint/printerProfiles/{{item.id}}.profile" loop: "{{ octoprint_printer_profiles }}" + become: true + become_user: "{{ octoprint_user }}" ################################################################################ # Octoprint Users ################################################################################ - - when: octoprint_register_config_stat.stat.exists - -- name: Register if user databse already exists on target host - stat: - path: "/home/{{ octoprint_user }}/.octoprint.users.yaml" - register: octoprint_register_users - -- name: Read default octoprint users - set_fact: - octoprint_defaut_users: "{{ lookup('file', 'users.yaml') | from_yaml }}" - -- name: Copy default users - copy: - src: users.yaml - dest: "/home/{{ octoprint_user }}/.octoprint/users.yaml" - when: not octoprint_register_users.stat.exists - -- name: Merge users database with default users +- name: Setup octoprint users block: - - name: Read Octoprint users file - slurp: - src: "/home/{{ octoprint_user }}/.octoprint/users.yaml" - register: octoprint_register_users_file + - name: Register if user databse already exists on target host + stat: + path: "/home/{{ octoprint_user }}/.octoprint.users.yaml" + register: octoprint_register_users - - name: Parse Octoprint users file - set_fact: - current_octoprint_users: "{{ octoprint_register_users_file['content'] | b64decode | from_yaml }}" - - - name: Merge current users with default users - set_fact: - octoprint_users_db: "{{ current_octoprint_users | combine(octoprint_default_users)}}" - - - name: Copy new users file + - name: Copy default users copy: - content: "{{ octoprint_users_db | to_nice_yaml }}" - dest: "/home/{{ octoprint_user }}/.octoprint.users.yaml" - when: octoprint_register_users.stat.exists + content: "{{ octoprint_users_list | to_nice_yaml }}" + dest: "/home/{{ octoprint_user }}/.octoprint/users.yaml" + when: not octoprint_register_users.stat.exists + + - name: Merge users database with default users + block: + - name: Read Octoprint users file + slurp: + src: "/home/{{ octoprint_user }}/.octoprint/users.yaml" + register: octoprint_register_users_file + + - name: Parse Octoprint users file + set_fact: + current_octoprint_users: "{{ octoprint_register_users_file['content'] | b64decode | from_yaml }}" + + - name: Merge current users with default users + set_fact: + octoprint_users_db: "{{ current_octoprint_users | combine(octoprint_users_list)}}" + + - name: Copy new users file + copy: + content: "{{ octoprint_users_db | to_nice_yaml }}" + dest: "/home/{{ octoprint_user }}/.octoprint/users.yaml" + when: octoprint_register_users.stat.exists + when: octoprint_users_list is defined + become: true + become_user: "{{ octoprint_user }}" + +################################################################################ +# Octoprint app keys +################################################################################ + +- name: Install application keys + block: + - name: Register existing app keys + stat: + path: /home/{{ octoprint_user }}/.octoprint/data/appkeys/keys.yaml + register: app_keys_file + + - name: Read existing app keys + slurp: + src: /home/{{ octoprint_user }}/.octoprint/data/appkeys/keys.yaml + register: existing_app_keys_content + when: app_keys_file.stat.exists + + - name: Combine local and remote app keys + set_fact: + app_keys_combined: "{{ existing_app_keys_content['content'] | b64decode | from_yaml | combine(octoprint_app_keys ,recursive=True) }}" + when: app_keys_file.stat.exists + + - name: Copy default app keys + copy: + content: "{{ app_keys_combined | to_nice_yaml }}" + dest: /home/{{ octoprint_user }}/.octoprint/data/appkeys/keys.yaml + when: app_keys_file.stat.exists + + - name: Copy default app keys + copy: + content: "{{ octoprint_app_keys | to_nice_yaml }}" + dest: /home/{{ octoprint_user }}/.octoprint/data/appkeys/keys.yaml + when: not app_keys_file.stat.exists + when: octoprint_app_keys is defined + notify: Restart octoprint + +################################################################################ +# Webcam +################################################################################ + +- name: Setup webcam + block: + - name: Install dependencies + apt: + name: + - ffmpeg + - ustreamer + + - name: Install systemd unit + template: src=ustreamer.service.j2 dest=/lib/systemd/system/ustreamer.service + notify: + - Reload systemd + - Restart ustreamer + + - name: Enable and start ustreamer + service: + name: ustreamer + state: started + enabled: yes + + when: octoprint_has_webcam ################################################################################ # Reverse proxy @@ -161,6 +272,7 @@ - name: Enable octoprint service: name: octoprint + state: started enabled: yes diff --git a/roles/octoprint/templates/config.yaml.j2 b/roles/octoprint/templates/config.yaml.j2 index d7f4d9e..a309496 100644 --- a/roles/octoprint/templates/config.yaml.j2 +++ b/roles/octoprint/templates/config.yaml.j2 @@ -6,6 +6,9 @@ appearance: accessControl: salt: "{{ octoprint_config_salt }}" autologinAs: binarykitchen + localNetworks: + - 127.0.0.0/8 + - 172.23.0.0/16 api: key: "{{ octoprint_config_api_key }}" diff --git a/roles/octoprint/templates/nginx_vhost.j2 b/roles/octoprint/templates/nginx_vhost.j2 index 6e8c4ae..fa8fe59 100644 --- a/roles/octoprint/templates/nginx_vhost.j2 +++ b/roles/octoprint/templates/nginx_vhost.j2 @@ -5,6 +5,13 @@ server { server_name {{ octoprint_domain }}; + location /webcam/ { + postpone_output 0; + proxy_buffering off; + proxy_ignore_headers X-Accel-Buffering; + proxy_pass http://localhost:8080/; + } + location / { client_max_body_size 1024M; proxy_set_header X-Real-IP $remote_addr; @@ -13,7 +20,6 @@ server { proxy_set_header Connection "upgrade"; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Scheme $scheme; - proxy_set_header X-Script-Name /octoprint; proxy_http_version 1.1; proxy_pass http://localhost:5000; } diff --git a/roles/octoprint/templates/octoprint.service.j2 b/roles/octoprint/templates/octoprint.service.j2 index 5a2a8b3..6035db1 100644 --- a/roles/octoprint/templates/octoprint.service.j2 +++ b/roles/octoprint/templates/octoprint.service.j2 @@ -7,7 +7,6 @@ After=network.target RestartSec=2s Type=simple User={{ octoprint_user }} -Group={{ octoprint_user }} WorkingDirectory={{ octoprint_dir }} ExecStart={{ octoprint_dir }}/bin/octoprint serve Restart=always diff --git a/roles/octoprint/templates/ustreamer.service.j2 b/roles/octoprint/templates/ustreamer.service.j2 new file mode 100644 index 0000000..5a5341f --- /dev/null +++ b/roles/octoprint/templates/ustreamer.service.j2 @@ -0,0 +1,19 @@ +[Unit] +Description=Ustreamer +After=syslog.target +After=network.target + +[Service] +RestartSec=2s +Type=simple +User={{ octoprint_user }} +Group={{ octoprint_user }} +{% if octoprint_ustreamer_args is defined %} +ExecStart=/usr/bin/ustreamer {{octoprint_ustreamer_args}} +{% else %} +ExecStart=/usr/bin/ustreamer +{% endif %} +Restart=always + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/site.yml b/site.yml index 7b960bf..a28043f 100644 --- a/site.yml +++ b/site.yml @@ -1,5 +1,5 @@ - name: Setup common rules - hosts: [3D_Printers] + hosts: [3D-Printers] roles: - common - root_keys @@ -7,4 +7,5 @@ - name: Setup octoprint hosts: [Octoprint_hosts] roles: - - octoprint \ No newline at end of file + - octoprint + tags: octoprint \ No newline at end of file