gsoft-inc / ansible-role-azure-devops-agent

An Ansible role that installs and configures a Linux machine to be used as an Azure DevOps build or deployment agent.
59 stars 72 forks source link

Install multiple agents on 1 server #53

Open andrescolodrero opened 2 years ago

andrescolodrero commented 2 years ago

Playbook could accept an array of agent names, so it is possible to have multiple agents in same server.

Actually, there is no possibility and adding a new name to the variables, will uninstall existing one.

andrescolodrero commented 2 years ago

Hi, this will download an create a new folder for a new agent. but it will be nice to have agent_name as an array az_devops_agent_name: "{{ ansible_hostname }}-agent1" az_devops_agent_folder: "/home/{{ az_devops_agent_user }}/{{ az_devops_agent_name }}/" az_devops_work_folder: "/home/{{ az_devops_agent_user }}/{{ az_devops_agent_name }}/_work"

andrew-sumner commented 2 years ago

I've worked around this using the following ansible:

- name: Check for agent service for {{ az_devops_agent_name }}
  ansible.windows.win_service_info:
    name: 'vstsagent.tfs.{{ az_devops_agent_pool_name }}.{{ az_devops_agent_name }}'
  register: service_info

# - debug:
#     var: service_info

# Removing chocolately lib allows installing multiple packages of same version
# See: https://github.com/chocolatey/choco/issues/1022
- name: Remove chocolatly lib folder azure-pipelines-agent.{{ az_devops_agent_version }}
  ansible.windows.win_file:
    path: 'C:\ProgramData\chocolatey\lib\azure-pipelines-agent.{{ az_devops_agent_version }}'
    state: absent
  when: service_info.exists == false or service_info.services[0].state != "started"

  # This role https://github.com/gsoft-inc/ansible-role-azure-devops-agent
  # Uses chocolaty package https://community.chocolatey.org/packages/azure-pipelines-agent
- name: Install Azure DevOps Agent {{ az_devops_agent_name }}
  include_role:
    name: gsoft.azure_devops_agent
    allow_duplicates: yes
  when: service_info.exists == false or service_info.services[0].state != "started"