|
| 1 | +--- |
| 2 | +- name: Install and configure rcloud REST API server |
| 3 | + hosts: localhost |
| 4 | + become: yes |
| 5 | + become_method: sudo |
| 6 | + tasks: |
| 7 | + - name: Ensure rcloud binary was built |
| 8 | + stat: |
| 9 | + path: "{{ playbook_dir }}/../workflows/rcloud/target/release/rcloud" |
| 10 | + register: rcloud_binary |
| 11 | + failed_when: not rcloud_binary.stat.exists |
| 12 | + |
| 13 | + - name: Install rcloud binary |
| 14 | + copy: |
| 15 | + src: "{{ playbook_dir }}/../workflows/rcloud/target/release/rcloud" |
| 16 | + dest: /usr/local/bin/rcloud |
| 17 | + mode: '0755' |
| 18 | + owner: root |
| 19 | + group: root |
| 20 | + |
| 21 | + - name: Create rcloud system user |
| 22 | + user: |
| 23 | + name: rcloud |
| 24 | + system: yes |
| 25 | + shell: /usr/sbin/nologin |
| 26 | + home: /var/lib/rcloud |
| 27 | + create_home: yes |
| 28 | + |
| 29 | + - name: Create rcloud configuration directory |
| 30 | + file: |
| 31 | + path: /etc/rcloud |
| 32 | + state: directory |
| 33 | + mode: '0755' |
| 34 | + owner: root |
| 35 | + group: root |
| 36 | + |
| 37 | + - name: Create systemd service file |
| 38 | + copy: |
| 39 | + dest: /etc/systemd/system/rcloud.service |
| 40 | + mode: '0644' |
| 41 | + owner: root |
| 42 | + group: root |
| 43 | + content: | |
| 44 | + [Unit] |
| 45 | + Description=rcloud REST API server for VM management |
| 46 | + Documentation=https://github.com/linux-kdevops/kdevops |
| 47 | + After=network.target libvirtd.service |
| 48 | + Requires=libvirtd.service |
| 49 | +
|
| 50 | + [Service] |
| 51 | + Type=simple |
| 52 | + User=rcloud |
| 53 | + Group=rcloud |
| 54 | + WorkingDirectory={{ topdir_path }} |
| 55 | + Environment="KDEVOPS_ROOT={{ topdir_path }}" |
| 56 | + Environment="RUST_LOG=info" |
| 57 | + Environment="RCLOUD_STORAGE_POOL_PATH={{ kdevops_storage_pool_path | default(libvirt_storage_pool_path) }}" |
| 58 | + Environment="RCLOUD_BASE_IMAGES_DIR={{ guestfs_base_image_dir }}" |
| 59 | + Environment="RCLOUD_LIBVIRT_URI={{ libvirt_uri | default('qemu:///system') }}" |
| 60 | + Environment="RCLOUD_NETWORK_BRIDGE={{ libvirt_bridge_name | default('default') }}" |
| 61 | + ExecStart=/usr/local/bin/rcloud |
| 62 | + Restart=on-failure |
| 63 | + RestartSec=5s |
| 64 | +
|
| 65 | + # Security hardening |
| 66 | + NoNewPrivileges=true |
| 67 | + PrivateTmp=true |
| 68 | + ProtectSystem=strict |
| 69 | + ProtectHome=true |
| 70 | + ReadWritePaths=/var/lib/rcloud {{ kdevops_storage_pool_path | default(libvirt_storage_pool_path) }} |
| 71 | + ReadOnlyPaths={{ topdir_path }} {{ kdevops_storage_pool_path | default(libvirt_storage_pool_path) }}/guestfs |
| 72 | +
|
| 73 | + [Install] |
| 74 | + WantedBy=multi-user.target |
| 75 | +
|
| 76 | + - name: Add rcloud user to libvirt-qemu group |
| 77 | + user: |
| 78 | + name: rcloud |
| 79 | + groups: "{{ libvirt_qemu_group | default('libvirt-qemu') }}" |
| 80 | + append: yes |
| 81 | + |
| 82 | + - name: Reload systemd daemon |
| 83 | + systemd: |
| 84 | + daemon_reload: yes |
| 85 | + |
| 86 | + - name: Enable rcloud service |
| 87 | + systemd: |
| 88 | + name: rcloud |
| 89 | + enabled: yes |
| 90 | + |
| 91 | + - name: Extract port from bind address |
| 92 | + set_fact: |
| 93 | + rcloud_port: "{{ (rcloud_server_bind | default('127.0.0.1:8765')).split(':')[1] }}" |
| 94 | + |
| 95 | + - name: Display service status instructions |
| 96 | + debug: |
| 97 | + msg: |
| 98 | + - "rcloud service installed successfully" |
| 99 | + - "Start the service with: sudo systemctl start rcloud" |
| 100 | + - "Check status with: sudo systemctl status rcloud" |
| 101 | + - "View logs with: sudo journalctl -u rcloud -f" |
| 102 | + - "" |
| 103 | + - "API will be available at: http://{{ rcloud_server_bind | default('127.0.0.1:8765') }}" |
| 104 | + - "" |
| 105 | + - "Test with:" |
| 106 | + - " curl http://localhost:{{ rcloud_port }}/api/v1/health" |
| 107 | + - " curl http://localhost:{{ rcloud_port }}/api/v1/status" |
0 commit comments