[switchboard] Add Ansible role install_test_machine_monitor.

Note that this uses the Makefile targets for //machine:

  https://skia.googlesource.com/buildbot/+/refs/heads/main/machine/Makefile#84

Bug: skia:12063
Change-Id: I1214de37c24be8c83fadeaeb760cc2a872708a40
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/434470
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/skolo/ansible/switchboard/roles/install_test_machine_monitor/README.md b/skolo/ansible/switchboard/roles/install_test_machine_monitor/README.md
new file mode 100644
index 0000000..146ec76
--- /dev/null
+++ b/skolo/ansible/switchboard/roles/install_test_machine_monitor/README.md
@@ -0,0 +1,31 @@
+# Role Name
+
+`install_test_machine_monitor`
+
+## Description
+
+Compiles and installs `test_machine_monitor` to the machine.
+
+## Variables Required
+
+Requires `gather_facts` to detect the target operating system.
+
+This role uses the `skolo_account` variable defined in
+`//skolo/ansible/group_vars/all.yml` and potentially overridden in `hosts.ini`.
+
+## Arguments
+
+Takes a single boolean argument `start_swarming` that controls whether or not
+`test_machine_monitor` should be passed the `--start_swarming` flag.
+
+## Example Playbook
+
+```
+# Install test_machine_monitor that doesn't launch Swarming.
+- hosts: "{{ variable_hosts | default('rpis') }}"
+  user: chrome-bot
+  gather_facts: yes
+
+  roles:
+    - { role: install_test_machine_monitor, start_swarming: false }
+```
diff --git a/skolo/ansible/switchboard/roles/install_test_machine_monitor/meta/argument_specs.yml b/skolo/ansible/switchboard/roles/install_test_machine_monitor/meta/argument_specs.yml
new file mode 100644
index 0000000..1f1adf8
--- /dev/null
+++ b/skolo/ansible/switchboard/roles/install_test_machine_monitor/meta/argument_specs.yml
@@ -0,0 +1,12 @@
+---
+argument_specs:
+  main:
+    short_description:
+      Arguments that can be passed to the install_test_machine_monitor role.
+    options:
+      start_swarming:
+        type: 'boolean'
+        required: false
+        default: false
+        description:
+          'If true then test_machine_monitor will also spawn swarming.'
diff --git a/skolo/ansible/switchboard/roles/install_test_machine_monitor/tasks/main.yml b/skolo/ansible/switchboard/roles/install_test_machine_monitor/tasks/main.yml
new file mode 100644
index 0000000..e59eaf1
--- /dev/null
+++ b/skolo/ansible/switchboard/roles/install_test_machine_monitor/tasks/main.yml
@@ -0,0 +1,37 @@
+---
+- name: Build test_machine_monitor for the target machine.
+  delegate_to: 127.0.0.1
+  make:
+    chdir: '{{ role_path }}/../../../../../machine/'
+    target:
+      "build_test_machine_monitor_{{ ansible_facts['architecture'] }}_{{
+      ansible_facts['system'] }}"
+
+- name: Copy over service file.
+  become: yes
+  template:
+    src: templates/test_machine_monitor.service
+    dest: /etc/systemd/system/test_machine_monitor.service
+    owner: root
+    group: root
+    mode: '0644'
+
+- name: Copy over executable.
+  become: yes
+  copy:
+    src:
+      "{{ role_path }}/../../../../../machine/build/{{ ansible_facts['system']
+      }}/{{ ansible_facts['architecture'] }}/test_machine_monitor"
+    dest: /usr/local/bin/test_machine_monitor
+    owner: root
+    group: root
+    mode: '0755'
+
+- name: Start systemd servce.
+  become: yes
+  systemd:
+    enabled: yes
+    # Do not force a restart, we'll just pick up the new version on reboot.
+    state: started
+    name: test_machine_monitor
+    daemon_reload: yes
diff --git a/skolo/ansible/switchboard/roles/install_test_machine_monitor/templates/test_machine_monitor.service b/skolo/ansible/switchboard/roles/install_test_machine_monitor/templates/test_machine_monitor.service
new file mode 100644
index 0000000..8b677ce
--- /dev/null
+++ b/skolo/ansible/switchboard/roles/install_test_machine_monitor/templates/test_machine_monitor.service
@@ -0,0 +1,22 @@
+[Unit]
+Description=test_machine_monitor
+After=syslog.target network.target
+
+[Service]
+Type=simple
+User=chrome-bot
+{% if start_swarming is true %}
+Environment=SWARMING_BOT_ID={{ ansible_facts['hostname'] }}
+{% endif %}
+ExecStart=/usr/local/bin/test_machine_monitor \
+   --config=prod.json \
+   --metadata_url=http://metadata/computeMetadata/v1/instance/service-accounts/default/token \
+   {% if start_swarming is true %}
+   --python_exe=/usr/bin/python3 \
+   --start_swarming \
+   {% endif %}
+   --username=chrome-bot
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
\ No newline at end of file