From 8e5d7cd99b46a1b148cc6dc5683fa0d4cbcdeba0 Mon Sep 17 00:00:00 2001 From: DanSibbernsen Date: Fri, 9 Dec 2022 15:57:42 -0600 Subject: [PATCH 1/3] fix(Windows): formatting package_params input to Chocolatey so they are treated like a list instead of a string. The package_params were effectively being ignored because of this. Correcting Ansible lint warnings: FQCN + use of 'true' instead of 'yes' --- tasks/Windows.yml | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tasks/Windows.yml b/tasks/Windows.yml index ceaedaa..72cf40a 100644 --- a/tasks/Windows.yml +++ b/tasks/Windows.yml @@ -4,10 +4,10 @@ password: "{{ az_devops_agent_password }}" state: present password_never_expires: true - become: yes + become: true when: + - az_devops_agent_create_local_user - - name: Ensure chocolatey is present win_chocolatey: name: chocolatey @@ -17,7 +17,7 @@ # https://github.com/flcdrg/au-packages/blob/master/azure-pipelines-agent/README.md - name: Set basic agent package parameters - set_fact: + ansible.builtin.set_fact: common_install_options: - "/Directory:{{ az_devops_agent_folder }}" - "/Url:{{ az_devops_server_url }}" @@ -41,55 +41,55 @@ - "/ProjectName:{{ az_devops_project_name }}" - name: Add '/Replace' configuration argument - set_fact: - common_install_options: "{{ common_install_options }} + ['/Replace']" + ansible.builtin.set_fact: + common_install_options: "{{ common_install_options + ['/Replace'] }}" when: - az_devops_agent_replace_existing - name: Add deployment group tags - set_fact: - deployment_install_options: "{{ deployment_install_options }} + ['/DeploymentGroupTags:{{ az_devops_deployment_group_tags }}']" + ansible.builtin.set_fact: + deployment_install_options: "{{ deployment_install_options + ['/DeploymentGroupTags:' + az_devops_deployment_group_tags] }}" when: - az_devops_deployment_group_tags is defined - name: Add az_devops_proxy_url - set_fact: - common_install_options: "{{ common_install_options }} + ['/ProxyUrl:{{ az_devops_proxy_url }}']" + ansible.builtin.set_fact: + common_install_options: "{{ common_install_options + ['/ProxyUrl:' + az_devops_proxy_url] }}" when: - az_devops_proxy_url is defined and az_devops_proxy_url - name: Add az_devops_proxy_username - set_fact: - common_install_options: "{{ common_install_options }} + ['/ProxyUserName:{{ az_devops_proxy_username }}']" + ansible.builtin.set_fact: + common_install_options: "{{ common_install_options + ['/ProxyUserName:' + az_devops_proxy_username] }}" when: - az_devops_proxy_username is defined and az_devops_proxy_username - name: Add az_devops_proxy_password - set_fact: - common_install_options: "{{ common_install_options }} + ['/ProxyPassword:{{ az_devops_proxy_password }}']" + ansible.builtin.set_fact: + common_install_options: "{{ common_install_options + ['/ProxyPassword:' + az_devops_proxy_password] }}" when: - az_devops_proxy_password is defined and az_devops_proxy_password - name: Configure agent as a build server - set_fact: - az_devops_agent_package_params: "{{ common_install_options }} + {{ build_agent_install_options }}" + ansible.builtin.set_fact: + az_devops_agent_package_params: "{{ common_install_options + build_agent_install_options }}" when: - az_devops_agent_role == 'build' - name: Configure agent as a deployment server - set_fact: - az_devops_agent_package_params: "{{ common_install_options }} + {{ deployment_install_options }}" + ansible.builtin.set_fact: + az_devops_agent_package_params: "{{ common_install_options + deployment_install_options }}" when: - az_devops_agent_role == 'deployment' - name: Configure agent as an environment resource - set_fact: - az_devops_agent_package_params: "{{ common_install_options }} + {{ resource_agent_install_options }}" + ansible.builtin.set_fact: + az_devops_agent_package_params: "{{ common_install_options + resource_agent_install_options }}" when: - az_devops_agent_role == 'resource' - name: Install azure-pipelines-agent package - win_chocolatey: + chocolatey.chocolatey.win_chocolatey: name: azure-pipelines-agent state: present version: "{{ az_devops_agent_version }}" From 0fd6dbd3d566bd200e3c512530a3646a728d8255 Mon Sep 17 00:00:00 2001 From: DanSibbernsen Date: Fri, 9 Dec 2022 16:27:48 -0600 Subject: [PATCH 2/3] fix(Windows): adjusting 'when' statements to check whether variables are actually populated before execution. Formatting them all the same way --- tasks/Windows.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tasks/Windows.yml b/tasks/Windows.yml index 72cf40a..43399e1 100644 --- a/tasks/Windows.yml +++ b/tasks/Windows.yml @@ -51,42 +51,46 @@ deployment_install_options: "{{ deployment_install_options + ['/DeploymentGroupTags:' + az_devops_deployment_group_tags] }}" when: - az_devops_deployment_group_tags is defined + - az_devops_deployment_group_tags - name: Add az_devops_proxy_url ansible.builtin.set_fact: common_install_options: "{{ common_install_options + ['/ProxyUrl:' + az_devops_proxy_url] }}" when: - - az_devops_proxy_url is defined and az_devops_proxy_url + - az_devops_proxy_url is defined + - az_devops_proxy_url - name: Add az_devops_proxy_username ansible.builtin.set_fact: common_install_options: "{{ common_install_options + ['/ProxyUserName:' + az_devops_proxy_username] }}" when: - - az_devops_proxy_username is defined and az_devops_proxy_username + - az_devops_proxy_username is defined + - az_devops_proxy_username - name: Add az_devops_proxy_password ansible.builtin.set_fact: common_install_options: "{{ common_install_options + ['/ProxyPassword:' + az_devops_proxy_password] }}" when: - - az_devops_proxy_password is defined and az_devops_proxy_password + - az_devops_proxy_password is defined + - az_devops_proxy_password - name: Configure agent as a build server ansible.builtin.set_fact: az_devops_agent_package_params: "{{ common_install_options + build_agent_install_options }}" when: - - az_devops_agent_role == 'build' + - az_devops_agent_role == 'build' - name: Configure agent as a deployment server ansible.builtin.set_fact: az_devops_agent_package_params: "{{ common_install_options + deployment_install_options }}" when: - - az_devops_agent_role == 'deployment' + - az_devops_agent_role == 'deployment' - name: Configure agent as an environment resource ansible.builtin.set_fact: az_devops_agent_package_params: "{{ common_install_options + resource_agent_install_options }}" when: - - az_devops_agent_role == 'resource' + - az_devops_agent_role == 'resource' - name: Install azure-pipelines-agent package chocolatey.chocolatey.win_chocolatey: From 5165a9dc5888007339afdfeb82ffb8f3e26e4e2e Mon Sep 17 00:00:00 2001 From: DanSibbernsen Date: Tue, 23 Apr 2024 11:44:30 -0500 Subject: [PATCH 3/3] feat(environment): adding environment resource tags to Windows deployments --- README.md | 7 ++++++- tasks/Windows.yml | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 96a7940..95fee22 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,9 @@ Available variables are listed below, along with default values (see `defaults/m az_devops_agent_pool_name: "Default" az_devops_agent_role: "build" az_devops_deployment_group_tags: null - az_devops_environment_name: null az_devops_deployment_group_name: null + az_devops_environment_name: null + az_devops_environment_tags: null az_devops_agent_replace_existing: false az_devops_reconfigure_agent: false az_devops_agent_user_capabilities: null @@ -105,6 +106,10 @@ Available variables are listed below, along with default values (see `defaults/m Use in conjuction with the `resource` agent role. The name of the environment in which to add the VM resource. **This needs to be manually created in you Azure DevOps project beforehand.** +- **az_devops_environment_tags** + + Use in conjuction with the `resource` agent role. Allows the user of tags to identify the agent (ex: QA, Staging, Prod, etc.) + - **az_devops_agent_replace_existing** Adds the `--replace` argument to the configuration script for the [scenario where you need to replace an exiting agent with a new host](https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/v2-linux?view=azure-devops#pool-and-agent-names). diff --git a/tasks/Windows.yml b/tasks/Windows.yml index 43399e1..69d9aed 100644 --- a/tasks/Windows.yml +++ b/tasks/Windows.yml @@ -53,6 +53,13 @@ - az_devops_deployment_group_tags is defined - az_devops_deployment_group_tags +- name: Add environment resource tags + ansible.builtin.set_fact: + resource_agent_install_options: "{{ resource_agent_install_options + ['/EnvironmentTags:' + az_devops_environment_tags] }}" + when: + - az_devops_environment_tags is defined + - az_devops_environment_tags + - name: Add az_devops_proxy_url ansible.builtin.set_fact: common_install_options: "{{ common_install_options + ['/ProxyUrl:' + az_devops_proxy_url] }}"