Answers: <p>If you have Docker on the machines which are hosting the github runners, and you have already registered them with the repos containing the pipelines which will execute them, you have a few options available:</p>
  <ol>
  <li>The easiest, but most invasive way of doing this is to use the machines as bare-metal provisioned. I would write an ansible role and playbook (this provides your declarative configuration) to turn a vanilla machine into a provisioned runner.</li>
  <li>If you create Github Actions, you can package them into containers (using the same Ansible role and playbook as above), and update your <code>workflow.yml</code> to use these actions or containers on the host. You will have to build the container that the workflow or action needs before. If you want to have a declarative configuration for these containers too, you can write a <a href="https://developer.hashicorp.com/packer/docs/templates/hcl_templates" rel="nofollow noreferrer">Packer template</a>.</li>
  <li>Finally, customise the the containers that are used by the runner: See <a href="https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/customizing-the-containers-used-by-jobs" rel="nofollow noreferrer">https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/customizing-the-containers-used-by-jobs</a>. You can use that to define mount points (for special licensed software, e.g.)</li>
  </ol>
  <p>So, to recap and respond directly to the question:</p>
  <blockquote>
  <p>is there a tool that can configure build agents</p>
  </blockquote>
  <p>My choice would be Ansible. Create a repo for the role and playbook. The actions in that repo will provision your hosts every time you merge to main. E.g. a new version of java is approved -&gt; you merge the PR -&gt; Github Actions run Ansible playbook -&gt; runners are now updated.</p>
  <p>Alternatively, you use that same Ansible role and playbook to provision containers which are referenced in the application's pipeline; put a Packer template in the same repo as the Ansible role and playbook.</p>
  
Answers: CC BY-SA 4.0
Answers: 2023-09-19T07:06:48.667Z
Answers: 2023-09-24T06:57:23.870Z
Answers: 2023-09-24T06:57:23.870Z
Answers: Bruce Becker
Body: <p>We assemble android application using GH Actions on self-hosted agents.
  Right now we upgraded a couple of libraries and now we need to use another JDK version.
  Issue is that right now we need to manually go through each agent and set up new JDK version there.</p>
  <p>I am wondering, maybe is there a tool that can configure build agents (or any machine, actually) (I am talking about installing tools, choosing their versions, etc.) in a declarative way.
  Like having yaml or any other type of file which has all required information and the tool will do anything required to meet requirements defined in a config file.</p>
  <p>Docker is already doing something like that, but it's not really declarative and it creates overhead, which is something we can not allow.</p>
  
Comments: CC BY-SA 4.0
Comments: 2023-09-18T15:45:54.433Z
Comments: You can provision runners on the fly if the infrastructure that you're using to host them has a decent API. I typically suggest doing this with a Terraform apply, given that you have existing assets (Terraform module and prebuilt image). What are you hosting your runners on?
Comments: Bruce Becker
Comments: CC BY-SA 4.0
Comments: 2023-09-18T21:40:05.840Z
Comments: Nothing fancy, it's just a couple of mac minis connected to Git Hub actions as self-hosted agents. 
  I have not looked deep into Terraform, but for the first glance it looks exactly like the tool I was looking for. Thanks!
Comments: Alevinevich
Comments: CC BY-SA 4.0
Comments: 2023-09-19T06:56:15.427Z
Comments: Thanks for the clarification. In that case, I'm sure you've already read [the docs](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners) for creating new runners. However, since your question was about _declatively configuring_ them. Slightly different.
Comments: Bruce Becker
Tags: <continuous-integration>
Title: How to declaratively configure self hosted build agents for CI?
UserDisplayName: Alevinevich
ThreadText: # How to declaratively configure self hosted build agents for CI?
  
  (Asked by: username_0 on 2023-09-18)
  
  We assemble android application using GH Actions on self-hosted agents.
  Right now we upgraded a couple of libraries and now we need to use another JDK version.
  Issue is that right now we need to manually go through each agent and set up new JDK version there.
  
  I am wondering, maybe is there a tool that can configure build agents (or any machine, actually) (I am talking about installing tools, choosing their versions, etc.) in a declarative way.
  Like having yaml or any other type of file which has all required information and the tool will do anything required to meet requirements defined in a config file.
  
  Docker is already doing something like that, but it's not really declarative and it creates overhead, which is something we can not allow.
  
  **Tags:** continuous-integration
  
  > **Comments:**
  > **username_1**: You can provision runners on the fly if the infrastructure that you're using to host them has a decent API. I typically suggest doing this with a Terraform apply, given that you have existing assets (Terraform module and prebuilt image). What are you hosting your runners on?  
  > **username_0**: Nothing fancy, it's just a couple of mac minis connected to Git Hub actions as self-hosted agents.  I have not looked deep into Terraform, but for the first glance it looks exactly like the tool I was looking for. Thanks!  
  > **username_1**: Thanks for the clarification. In that case, I'm sure you've already read [the docs](https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/adding-self-hosted-runners) for creating new runners. However, since your question was about _declatively configuring_ them. Slightly different.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-09-19. Score: 0 | Accepted answer
  
  If you have Docker on the machines which are hosting the github runners, and you have already registered them with the repos containing the pipelines which will execute them, you have a few options available:
  
  1. The easiest, but most invasive way of doing this is to use the machines as bare-metal provisioned. I would write an ansible role and playbook (this provides your declarative configuration) to turn a vanilla machine into a provisioned runner.
  2. If you create Github Actions, you can package them into containers (using the same Ansible role and playbook as above), and update your `workflow.yml` to use these actions or containers on the host. You will have to build the container that the workflow or action needs before. If you want to have a declarative configuration for these containers too, you can write a [Packer template](https://developer.hashicorp.com/packer/docs/templates/hcl_templates).
  3. Finally, customise the the containers that are used by the runner: See <https://docs.github.com/en/actions/hosting-your-own-runners/managing-self-hosted-runners/customizing-the-containers-used-by-jobs>. You can use that to define mount points (for special licensed software, e.g.)
  
  So, to recap and respond directly to the question:
  
  > is there a tool that can configure build agents
  
  My choice would be Ansible. Create a repo for the role and playbook. The actions in that repo will provision your hosts every time you merge to main. E.g. a new version of java is approved -> you merge the PR -> Github Actions run Ansible playbook -> runners are now updated.
  
  Alternatively, you use that same Ansible role and playbook to provision containers which are referenced in the application's pipeline; put a Packer template in the same repo as the Ansible role and playbook.
  
  
  ---
  
  