Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu 22.04 & backport other PRs #75

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ Available variables are listed below, along with default values (see `defaults/m
az_devops_accountname: null
az_devops_accesstoken: null
az_devops_project_name: null
az_devops_agent_version: 2.188.3
az_devops_agent_version: 2.218.1
az_devops_agent_user: "az_devops_agent"
az_devops_agent_group: "az_devops_agent"
az_devops_agent_uid: null
az_devops_agent_gid: null
az_devops_agent_name: "{{ ansible_hostname }}"
az_devops_server_url: "https://dev.azure.com/{{ az_devops_accountname }}"
az_devops_agent_folder: "/home/{{ az_devops_agent_user }}/agent/"
Expand Down Expand Up @@ -69,6 +71,10 @@ Available variables are listed below, along with default values (see `defaults/m

Default group of the user used to run and configure the service.

- **az_devops_agent_gid**

GID of the user group used to run and configure the service.

- **az_devops_agent_name**

Name of the agent shown in Azure DevOps (defaults to the name of the host.).
Expand Down
5 changes: 4 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
az_devops_agent_version: 2.188.3
---
az_devops_agent_version: 2.218.1
az_devops_agent_user: "az_devops_agent"
az_devops_agent_name: "{{ ansible_hostname }}"
az_devops_server_url: "https://dev.azure.com/{{ az_devops_accountname }}/"
Expand All @@ -18,3 +19,5 @@ az_devops_proxy_url: null
az_devops_proxy_username: null
az_devops_proxy_password: null
az_devops_agent_create_local_user: true
az_devops_agent_legacy_dependencies: []
...
18 changes: 12 additions & 6 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
---
galaxy_info:
role_name: azure_devops_agent
author: Yohan Belval
author: gsoft
description: Azure DevOps Agent for Linux.
company: GSoft
standalone: true

license: "license (Apache-2.0)"

min_ansible_version: 2.4
min_ansible_version: "2.10"

platforms:
- name: Ubuntu
versions:
- xenial
- bionic
- focal
- jammy
- name: EL
versions:
- 7
- "7"
- "8"
- name: Debian
versions:
- stretch
- buster
- bullseye
- name: Windows
versions:
- 2016
- 2019
- "2016"
- "2019"
- name: MacOSX
versions:
- 10.15
- "10.15"

galaxy_tags:
- azure
Expand All @@ -37,3 +42,4 @@ galaxy_info:
- deployment
- ci
- cd
...
84 changes: 52 additions & 32 deletions tasks/Darwin.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
---
- name: Add an agent group {{ az_devops_agent_group }}
ansible.builtin.group:
name: "{{ az_devops_agent_group }}"
gid: "{{ az_devops_agent_gid | default(omit) }}"
state: present
become: true

- name: Add an agent user
user:
ansible.builtin.user:
name: "{{ az_devops_agent_user }}"
comment: "Azure DevOps Agent"
shell: /bin/zsh
group: "{{ az_devops_agent_group }}"
uid: "{{ az_devops_agent_uid|default(omit) }}"
uid: "{{ az_devops_agent_uid | default(omit) }}"
become: true

- name: Create directories
file:
ansible.builtin.file:
state: directory
path: "{{ item }}"
owner: "{{ az_devops_agent_user }}"
Expand All @@ -25,7 +33,7 @@
# even then doesn't use the provided gnu tar.
# Makes using ansible on macos a questionable endeavor (but some of us are left with that)...
- name: Download agent
get_url:
ansible.builtin.get_url:
url: "{{ az_devops_agent_package_url }}"
dest: "{{ az_devops_default_agent_local_package }}"
owner: "{{ az_devops_agent_user }}"
Expand All @@ -35,33 +43,33 @@
become: true

- name: Unarchive agent
shell: "cd {{ az_devops_agent_folder }} && tar -zxf {{ az_devops_default_agent_local_package }}"
ansible.builtin.shell: "cd {{ az_devops_agent_folder }} && tar -zxf {{ az_devops_default_agent_local_package }}"
become: true
become_user: "{{ az_devops_agent_user }}"
when: agent_download.changed or agent_directory.changed
tags: ['skip_ansible_lint']

- name: Check if svc.sh exists
stat:
ansible.builtin.stat:
path: "{{ '/'.join((az_devops_agent_folder, 'svc.sh')) }}"
register: svc_sh
become: true
changed_when: false
check_mode: no
check_mode: false

- name: Check service status
command: ./svc.sh status
ansible.builtin.command: ./svc.sh status
become: true
become_user: "{{ az_devops_agent_user }}"
args:
chdir: "{{ az_devops_agent_folder }}"
register: svc_status
changed_when: false
check_mode: no
check_mode: false
when: svc_sh.stat.exists

- name: Set agent config facts
set_fact:
ansible.builtin.set_fact:
agent_cmd_args:
- "./config.sh"
- "--unattended"
Expand All @@ -88,21 +96,25 @@
reconfigure_or_replace: "{{ az_devops_reconfigure_agent or az_devops_agent_replace_existing }}"

- name: Add deployment group tags
set_fact:
deployment_agent_cmd_args: "{{ deployment_agent_cmd_args }} +
['--addDeploymentGroupTags', '--deploymentGroupTags \\'{{ az_devops_deployment_group_tags }}\\'']"
ansible.builtin.set_fact:
deployment_agent_cmd_args: "{{ deployment_agent_cmd_args + ['--addDeploymentGroupTags', '--deploymentGroupTags', az_devops_deployment_group_tags] }}"
when:
- az_devops_deployment_group_tags is defined and az_devops_deployment_group_tags != None

- name: Set proxy url
ansible.builtin.set_fact:
agent_cmd_args: "{{ agent_cmd_args + ['--proxyurl', az_devops_proxy_url] }}"
when:
- az_devops_deployment_group_tags is defined
- az_devops_proxy_url is defined and az_devops_proxy_url != None

- name: Set proxy
set_fact:
agent_cmd_args: "{{ agent_cmd_args }} + ['--proxyurl \\'{{ az_devops_proxy_url }}\\'',
'--proxyusername \\'{{ az_devops_proxy_username }}\\'', '--proxypassword \\'{{ az_devops_proxy_password }}\\'']"
- name: Set proxy username and password
ansible.builtin.set_fact:
agent_cmd_args: "{{ agent_cmd_args + ['--proxyusername', az_devops_proxy_username, '--proxypassword', az_devops_proxy_password] }}"
when:
- az_devops_proxy_url is defined
- az_devops_proxy_url is defined and az_devops_proxy_url != None and az_devops_proxy_username != None and az_devops_proxy_password != None

- name: Uninstall agent service
command: ./svc.sh uninstall
ansible.builtin.command: ./svc.sh uninstall
become: true
become_user: "{{ az_devops_agent_user }}"
args:
Expand All @@ -113,7 +125,7 @@
- reconfigure_or_replace

- name: Unconfigure agent
command: "./config.sh remove --auth PAT --token {{ az_devops_accesstoken }}"
ansible.builtin.command: "./config.sh remove --auth PAT --token {{ az_devops_accesstoken }}"
args:
chdir: "{{ az_devops_agent_folder }}"
removes: "{{ az_devops_agent_folder }}/.agent"
Expand All @@ -124,15 +136,15 @@
- reconfigure_or_replace

- name: Add '--replace' configuration argument
set_fact:
build_agent_cmd_args: "{{ build_agent_cmd_args }} + ['--replace']"
deployment_agent_cmd_args: "{{ build_agent_cmd_args }} + ['--replace']"
resource_agent_cmd_args: "{{ resource_agent_cmd_args }} + ['--replace']"
ansible.builtin.set_fact:
build_agent_cmd_args: "{{ build_agent_cmd_args + ['--replace'] }}"
deployment_agent_cmd_args: "{{ build_agent_cmd_args + ['--replace'] }}"
resource_agent_cmd_args: "{{ resource_agent_cmd_args + ['--replace'] }}"
when:
- az_devops_agent_replace_existing

- name: Configure agent as a build server
command: "{{ (agent_cmd_args + build_agent_cmd_args) | join(' ') }}"
ansible.builtin.command: "{{ (agent_cmd_args + build_agent_cmd_args) | join(' ') }}"
args:
chdir: "{{ az_devops_agent_folder }}"
creates: "{{ az_devops_agent_folder }}/.agent"
Expand All @@ -143,7 +155,7 @@
- (not service_is_installed) or reconfigure_or_replace

- name: Configure agent as a deployment server
command: "{{ (agent_cmd_args + deployment_agent_cmd_args) | join(' ') }}"
ansible.builtin.command: "{{ (agent_cmd_args + deployment_agent_cmd_args) | join(' ') }}"
args:
chdir: "{{ az_devops_agent_folder }}"
creates: "{{ az_devops_agent_folder }}/.agent"
Expand All @@ -154,7 +166,7 @@
- (not service_is_installed) or reconfigure_or_replace

- name: Configure agent as an environment resource
command: "{{ (agent_cmd_args + resource_agent_cmd_args) | join(' ') }}"
ansible.builtin.command: "{{ (agent_cmd_args + resource_agent_cmd_args) | join(' ') }}"
args:
chdir: "{{ az_devops_agent_folder }}"
creates: "{{ az_devops_agent_folder }}/.agent"
Expand All @@ -165,19 +177,23 @@
- (not service_is_installed) or reconfigure_or_replace

- name: Set provided user defined capabilities
ini_file:
community.general.ini_file:
path: "{{ az_devops_agent_folder }}/.env"
section: null
option: "{{ item.key }}"
value: "{{ item.value }}"
no_extra_spaces: yes
no_extra_spaces: true
owner: "{{ az_devops_agent_user }}"
group: "{{ az_devops_agent_group }}"
mode: "0640"
loop: "{{ az_devops_agent_user_capabilities | default({}) | dict2items }}"
become: true

- name: Install agent service
command: ./svc.sh install {{ az_devops_agent_user }}
ansible.builtin.command: ./svc.sh install {{ az_devops_agent_user }}
register: agent_install
failed_when: agent_install.rc != 0
changed_when: agent_install.rc == 0
become: true
become_user: "{{ az_devops_agent_user }}"
args:
Expand All @@ -186,10 +202,14 @@
- (not service_is_installed) or reconfigure_or_replace

- name: Start agent service
command: ./svc.sh start
ansible.builtin.command: ./svc.sh start
register: agent_start
failed_when: agent_start.rc != 0
changed_when: agent_start.rc == 0
become: true
become_user: "{{ az_devops_agent_user }}"
args:
chdir: "{{ az_devops_agent_folder }}"
when:
- (not service_is_running) or reconfigure_or_replace
...
Loading