Skip to content

Set up Azure DevOps self-hosted agent on Ubuntu20.04. VM gets provisioned with Vagrant, which next executes Ansible playbook to install and configure Azure DevOps agent and packages required to run jobs (Git, Docker, K8s, Azure CLI, .NET Core, Python 3, NodeJS, Java). Agent auto-start enabled.

Notifications You must be signed in to change notification settings

IriW/azure-devops-self-hosted-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Self-hosted Azure DevOps agent (running on Ubuntu20.04LTS)

Prerequisites:

  • Vagrant installed locally
  • Python 3 installed locally
  • Ansible installed locally
  • Git installed locally
  • Variables declared

To trigger installation and configuration run vagrant up from your local repository directory.

Azure DevOps PAT

Azure DevOps Personal Access Token creation:

In your organization https://dev.azure.com/YOUR_ORGANIZATION_NAME/_usersSettings/tokens add new token:

  • Scope: Agent Pools (read, manage). Make sure all the other boxes are cleared. -> my default case here.
  • If it's deployment group agent, define scope: Deployment group (read, manage). Make sure all the other boxes are cleared.
  • If you want to add your agent to some other Agent Pool then default - make sure to provide correct name.

Vagrantfile

  • Creates Ubuntu20.04LTS VM locally.
  • Uses key created by Vagrant.
  • Creates VM with dynamically assigned IP (my network doesn't have static IP assigned, so this is a workaround). Due to that fact, Vagrant needs to publish the VM hostname on the network, which by next VM runs resolves the hostname azdevops-ubuntu20-agent.local to the correct IP by Avahi daemon, whatever the IP is.
  • Uses ansible to provision & configure Azure DevOps self-hosted agent.

Ansible playbook runs roles, which:

  • Update package cache and all packages.
  • Installs software such as: Git, Azure CLI, Python 3, Docker, .NET Core, Node.js, and Java, Kubernetes.
  • Downloads agent files from Azure DevOps portal and runs installation passing variables to target environment.
  • Configures agent auto-start after each system reboot.
  • Uses variables declared in /vars/main.yml specified in roles where it is necessary.
  • The agent is not assigned to a single organization, but listens to jobs request in each project in organization (for changes/adjustmens read further).
  • Installs and configures Avahi daemon on self-hosted agent VM (uses avahi.conf.j2 provided in the same directory, where ansible playbook is).

Kubernetes - to install or not to install

  • For building Kubernetes infrastructure using Azure DevOps pipelines, and BE ABLE TO TEST it by deploying apps to the built infrastructure, installation of Kubernetes on self-hosted agent is MANDATORY.

  • For building the infrastructure and NOT TESTING it, Kubernetes installation is NOT needed. Instead, use Azure DevOps to create the necessary resources in cloud (such as AKS clusters or AKS node pools) and use other tools/processes to deploy apps to those resources. If this is your case, just remove/comment related tasks: Install Kubernetes dependencies, Add the Kubernetes GPG key, Add the Kubernetes package repository, Install the Kubernetes packages.

Alternative self-hosted agent configuration (multiple projects)

Configure agent to listen to DIFFERENT projects:

Do not pass any --project in azure-devops-agent role, just omit it.

It will then listen if any job requests are posted across all projects in organization.

Configure agent to listen to SINGLE project:

Define variable for project and pass parameter with that variable as: --project {{ AZDEVOPS_PROJECT_NAME1 }} in azure-devops-agent role.

Configure agent to listen to SPECIFIED projects:

Adjust Configure the Azure DevOps agent task in azure-devops-agent role adding parameter:

--project {{ AZDEVOPS_PROJECT_NAME1 }},{{ AZDEVOPS_PROJECT_NAME2 }},{{ AZDEVOPS_PROJECT_NAME2 }}

Before running the playbook, make sure you have declared all the required variables.

Tested with the following software versions installed on host instance:

  • Vagrant 2.2.19
  • Ansible 2.10.8
  • Python 3.10.6

About

Set up Azure DevOps self-hosted agent on Ubuntu20.04. VM gets provisioned with Vagrant, which next executes Ansible playbook to install and configure Azure DevOps agent and packages required to run jobs (Git, Docker, K8s, Azure CLI, .NET Core, Python 3, NodeJS, Java). Agent auto-start enabled.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages