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.
60 stars 72 forks source link

Error when provisioning build agent - Templating type error #72

Open dendle opened 2 years ago

dendle commented 2 years ago

Hello All,

I get the following error when running this role on ubuntu-focal-20.04.

TASK [gsoft.azure_devops_agent : Configure agent as a build server] ************
fatal: [default]: FAILED! => {"msg": "Unexpected templating type error occurred on ({{ (agent_cmd_args + build_agent_cmd_args) | join(' ') }}): can only concatenate str (not \"list\") to str"}

It appears to be concatenating two lists, which are properly defined - I have no idea whats wrong!

Can anyone help?

Thanks, Matt

thebtm commented 1 year ago

I also get this same error when deploying to RHEL 8.

thebtm commented 1 year ago

After doing some debugging, I have noticed that the Set Proxy task is trying to append lists together but for some reason, its converting it to a string. I commented out the Set Proxy tasks and was able to get past the error. Not sure why Ansible is making the string conversion. more toubleshooting will be required to figure out how to fix this but if you don't depend on the proxy step, comment it out on your downloaded tasks.

- 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 }}\\'']"
  when:
    - az_devops_proxy_url is defined
sancfc commented 1 year ago

I have exactly the same error, CentOS 8 and ansible 2.13.3 and you?

mkoertgen commented 1 year ago

Same for me. Looks like adding lists should be moved inside the {{ }}. At least according to the Jinja2 docs

However, this might also need native types as formulated here

Digging deeper into this.

Ansible / Jinja2 is not really meant to be juggling with dynamic argument lists. Also there is lots of redundant duplications in the respective tasks (darwin, linux, windows).

Al-thi commented 1 year ago

A working configuration for proxy facts :

 - name: Set proxy
  block:
    - name: Set proxy facts
      ansible.builtin.set_fact:
        agent_proxy_args:
          - "--proxyurl + '{{ az_devops_proxy_url }}'"
          - "--proxyusername + '{{ az_devops_proxy_username }}'"
          - "--proxypassword + '{{ az_devops_proxy_password }}'"
    - name: Append proxy configuration to agent commands
      ansible.builtin.set_fact:
        agent_cmd_args: "{{ agent_cmd_args + agent_proxy_args }}"
  when:
    - az_devops_proxy_url is not none
mlgitdev commented 4 months ago

I used the above suggestion for others:

#...

- name: Set Agent config facts combined
  set_fact:
    build_server_cmd_args: "{{ agent_cmd_args + build_agent_cmd_args }}"
    deployment_server_cmd_args: "{{ agent_cmd_args + deployment_agent_cmd_args }}"
    resource_server_cmd_args: "{{ agent_cmd_args + resource_agent_cmd_args }}"
#...

- name: Configure agent as a build server
  command: "{{ build_server_cmd_args | join(' ') }}"
  args:
    chdir: "{{ az_devops_agent_folder }}"
    creates: "{{ az_devops_agent_folder }}/.agent"
  become: true
  become_user: "{{ az_devops_agent_user }}"
  when:
    - az_devops_agent_role == 'build'
    - (not service_is_installed) or reconfigure_or_replace

- name: Configure agent as a deployment server
  command: "{{ deployment_server_cmd_args | join(' ') }}"
  args:
    chdir: "{{ az_devops_agent_folder }}"
    creates: "{{ az_devops_agent_folder }}/.agent"
  become: true
  become_user: "{{ az_devops_agent_user }}"
  when:
    - az_devops_agent_role == 'deployment'
    - (not service_is_installed) or reconfigure_or_replace

- name: Configure agent as an environment resource
  command: "{{ resource_server_cmd_args | join(' ') }}"
  args:
    chdir: "{{ az_devops_agent_folder }}"
    creates: "{{ az_devops_agent_folder }}/.agent"
  become: true
  become_user: "{{ az_devops_agent_user }}"
  when:
    - az_devops_agent_role == 'resource'
    - (not service_is_installed) or reconfigure_or_replace