---
- name: Use azure arc agent to connect to azure
  become: true
  ansible.builtin.command:
    argv:
      - azcmagent
      - connect
      - --resource-group
      - "{{ azure_arc_resource_group }}"
      - --tenant-id
      - "{{ azure_arc_tenant_id }}"
      - --location
      - "{{ azure_arc_location }}"
      - --subscription-id
      - "{{ azure_arc_subscription_id }}"
      - --cloud
      - "{{ azure_arc_cloud }}"
      - --tags
      - "{{ azure_arc_processed_tags }}"
      - --access-token
      - "{{ azure_arc_access_token.access_token }}"
      - --correlation-id
      - "{{ azure_arc_correlation_id }}"
      - --json
  no_log: true
  # If this command is run, it will always change the connection status from unconnected to connected
  changed_when: true
  failed_when: false
  register: azure_arc_azcmagent_connect_json
