--- # config.yml is a TEMPLATE now, not a one-shot `generate-config`. # # Before this, the file was generated on first deploy and never touched again, # so the repo had no say in anything inside it - including container.docker_host, # which is the setting that decides whether jobs can use Docker at all. The # alternative was patching keys in place with a regex, which in a YAML file # with repeated key names under different parents is the kind of thing that # works until it silently does not. # # owner/group/mode are runner:runner 0644, read off the live box, matching what # `generate-config` plus the old chown produced. Nothing secret is in here; the # registration token lives in .runner. - name: Write the forgejo-runner configuration ansible.builtin.template: src: config.yml.j2 dest: "{{ forgejo_runner_config_path }}" owner: "{{ forgejo_runner_user }}" group: "{{ forgejo_runner_user }}" mode: '0644' # A malformed config is a runner that will not start. Catch it here, while # the old file is still in place, rather than after it has been replaced. validate: "python3 -c \"import yaml,sys; yaml.safe_load(open(sys.argv[1]))\" %s" notify: Restart forgejo-runner # ── Register runner ──────────────────────────────────────────────────────── # Registration is separate from configuration and happens once. The labels are # frozen into .runner at this point; changing forgejo_runner_labels later does # not move them, which is why the label set is left exactly as it was. - name: Check if runner is already registered stat: path: "{{ forgejo_runner_dir }}/.runner" register: runner_stat - name: Register runner with Forgejo instance command: > {{ forgejo_runner_bin_path }} register --no-interactive --instance {{ forgejo_instance_url }} --token {{ forgejo_runner_registration_token }} --name forgejo-runner-box --labels "{{ forgejo_runner_labels }}" args: chdir: "{{ forgejo_runner_dir }}" when: not runner_stat.stat.exists - name: Set runner registration file ownership file: path: "{{ forgejo_runner_dir }}/.runner" owner: "{{ forgejo_runner_user }}" group: "{{ forgejo_runner_user }}" when: not runner_stat.stat.exists