azure.azcollection.azure_rm_monitordiagnosticsetting (2.3.0) — module

Create, update, or manage Azure Monitor diagnostic settings.

| "added in version" 1.10.0 of azure.azcollection"

Authors: Ross Bender (@l3ender)

Install collection

Install with ansible-galaxy collection install azure.azcollection:==2.3.0


Add to requirements.yml

  collections:
    - name: azure.azcollection
      version: 2.3.0

Description

Create, update, or manage Azure Monitor diagnostic settings for any type of resource.


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create storage-based diagnostic setting for a virtual network
  azure_rm_monitordiagnosticsetting:
    name: "logs-storage"
    resource: "{{ vnet_output.state.id }}"
    storage_account: "{{ storage_output.state.id }}"
    logs:
      - category_group: "allLogs"
    metrics:
      - category: "AllMetrics"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Create diagnostic setting for webapp with log analytics, event hub, and storage
  azure_rm_monitordiagnosticsetting:
    name: "webapp-logs"
    resource:
      name: "my-webapp"
      type: "Microsoft.Web/sites"
      resource_group: "my-webapp-resource-group"
    event_hub:
      namespace: "my-event-hub"
      policy: "RootManageSharedAccessKey"
    log_analytics:
      name: "my-log-analytics-workspace"
      resource_group: "my-log-analytics-workspace-resource-group"
    storage_account:
      name: "mystorageaccount"
    logs:
      - category: "AppServiceHTTPLogs"
      - category: "AppServiceConsoleLogs"
      - category: "AppServiceAppLogs"
      - category: "AppServiceAuditLogs"
      - category: "AppServiceIPSecAuditLogs"
      - category: "AppServicePlatformLogs"
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Delete diagnostic setting
  azure_rm_monitordiagnosticsetting:
    name: "webapp-logs"
    resource:
      name: "my-webapp"
      type: "Microsoft.Web/sites"
      resource_group: "my-webapp-resource-group"
    state: "absent"

Inputs

    
logs:
    description:
    - The list of log setttings.
    - At least one of I(metrics) or I(logs) must be specified for the diagnostic setting.
    elements: dict
    suboptions:
      category:
        description:
        - Name of a Management Group Diagnostic Log category for a resource type this
          setting is applied to.
        type: str
      category_group:
        description:
        - Name of a Management Group Diagnostic Log category group for a resource type
          this setting is applied to.
        type: str
      enabled:
        default: true
        description:
        - Whether the log is enabled.
        type: bool
      retention_policy:
        description:
        - The retention policy for this log.
        suboptions:
          days:
            default: 0
            description:
            - The number of days for the retention policy.
            type: int
          enabled:
            default: true
            description:
            - Whether the retention policy is enabled.
            type: bool
        type: dict
    type: list

name:
    description:
    - The name of the diagnostic settings.
    required: true
    type: str

state:
    choices:
    - absent
    - present
    default: present
    description:
    - State of the private endpoint DNS zone group. Use C(present) to create or update
      and C(absent) to delete.
    type: str

secret:
    description:
    - Azure client secret. Use when authenticating with a Service Principal.
    type: str

tenant:
    description:
    - Azure tenant ID. Use when authenticating with a Service Principal.
    type: str

ad_user:
    description:
    - Active Directory username. Use when authenticating with an Active Directory user
      rather than service principal.
    type: str

metrics:
    description:
    - The list of metric setttings.
    - At least one of I(metrics) or I(logs) must be specified for the diagnostic setting.
    elements: dict
    suboptions:
      category:
        description:
        - Name of a Diagnostic Metric category for a resource type this setting is applied
          to.
        type: str
      enabled:
        default: true
        description:
        - Whether the metric category is enabled.
        type: bool
      retention_policy:
        description:
        - The retention policy for this metric.
        suboptions:
          days:
            default: 0
            description:
            - The number of days for the retention policy.
            type: int
          enabled:
            default: true
            description:
            - Whether the retention policy is enabled.
            type: bool
        type: dict
    type: list

profile:
    description:
    - Security profile found in ~/.azure/credentials file.
    type: str

log_mode:
    description:
    - Parent argument.
    type: str

log_path:
    description:
    - Parent argument.
    type: str

password:
    description:
    - Active Directory user password. Use when authenticating with an Active Directory
      user rather than service principal.
    type: str

resource:
    description:
    - The resource which will be monitored with the diagnostic setting.
    - It can be a string containing the resource ID.
    - It can be a dictionary containing I(name), I(type), I(resource_group), and optionally
      I(subscription_id).
    - I(name). The resource name.
    - I(type). The resource type including namespace, such as 'Microsoft.Network/virtualNetworks'.
    - I(resource_group). The resource group containing the resource.
    - I(subscription_id). The subscription ID containing the resource. If none is specified,
      the credential's subscription ID will be used.
    required: true
    type: raw

client_id:
    description:
    - Azure client ID. Use when authenticating with a Service Principal or Managed Identity
      (msi).
    - Can also be set via the C(AZURE_CLIENT_ID) environment variable.
    type: str

event_hub:
    description:
    - An event hub which will receive the diagnostic logs.
    - At least one of I(storage_account), I(log_analytics), or I(event_hub) must be specified
      for the diagnostic setting.
    suboptions:
      hub:
        description:
        - An event hub name to receive logs. If none is specified, the default event hub
          will be selected.
        type: str
      namespace:
        description:
        - The event hub namespace.
        required: true
        type: str
      policy:
        description:
        - The shared access policy.
        required: true
        type: str
      resource_group:
        description:
        - The resource group containing the event hub. If none is specified, the resource
          group of the I(resource) parameter will be used.
        type: str
      subscription_id:
        description:
        - The subscription ID containing the event hub. If none is specified, the subscription
          ID of the I(resource) parameter will be used.
        type: str
    type: dict

thumbprint:
    description:
    - The thumbprint of the private key specified in I(x509_certificate_path).
    - Use when authenticating with a Service Principal.
    - Required if I(x509_certificate_path) is defined.
    type: str
    version_added: 1.14.0
    version_added_collection: azure.azcollection

api_profile:
    default: latest
    description:
    - Selects an API profile to use when communicating with Azure services. Default value
      of C(latest) is appropriate for public clouds; future values will allow use with
      Azure Stack.
    type: str
    version_added: 0.0.1
    version_added_collection: azure.azcollection

auth_source:
    choices:
    - auto
    - cli
    - credential_file
    - env
    - msi
    default: auto
    description:
    - Controls the source of the credentials to use for authentication.
    - Can also be set via the C(ANSIBLE_AZURE_AUTH_SOURCE) environment variable.
    - When set to C(auto) (the default) the precedence is module parameters -> C(env)
      -> C(credential_file) -> C(cli).
    - When set to C(env), the credentials will be read from the environment variables
    - When set to C(credential_file), it will read the profile from C(~/.azure/credentials).
    - When set to C(cli), the credentials will be sources from the Azure CLI profile.
      C(subscription_id) or the environment variable C(AZURE_SUBSCRIPTION_ID) can be used
      to identify the subscription ID if more than one is present otherwise the default
      az cli subscription is used.
    - When set to C(msi), the host machine must be an azure resource with an enabled MSI
      extension. C(subscription_id) or the environment variable C(AZURE_SUBSCRIPTION_ID)
      can be used to identify the subscription ID if the resource is granted access to
      more than one subscription, otherwise the first subscription is chosen.
    - The C(msi) was added in Ansible 2.6.
    type: str
    version_added: 0.0.1
    version_added_collection: azure.azcollection

log_analytics:
    description:
    - A log analytics workspace which will receive the diagnostic logs.
    - It can be a string containing the log analytics workspace resource ID.
    - It can be a dictionary containing I(name) and optionally I(subscription_id) and
      I(resource_group).
    - At least one of I(storage_account), I(log_analytics), or I(event_hub) must be specified
      for the diagnostic setting.
    type: raw

storage_account:
    description:
    - A storage account which will receive the diagnostic logs.
    - It can be a string containing the storage account resource ID.
    - It can be a dictionary containing I(name) and optionally I(subscription_id) and
      I(resource_group).
    - At least one of I(storage_account), I(log_analytics), or I(event_hub) must be specified
      for the diagnostic setting.
    type: raw

subscription_id:
    description:
    - Your Azure subscription Id.
    type: str

cloud_environment:
    default: AzureCloud
    description:
    - For cloud environments other than the US public cloud, the environment name (as
      defined by Azure Python SDK, eg, C(AzureChinaCloud), C(AzureUSGovernment)), or a
      metadata discovery endpoint URL (required for Azure Stack). Can also be set via
      credential file profile or the C(AZURE_CLOUD_ENVIRONMENT) environment variable.
    type: str
    version_added: 0.0.1
    version_added_collection: azure.azcollection

adfs_authority_url:
    description:
    - Azure AD authority url. Use when authenticating with Username/password, and has
      your own ADFS authority.
    type: str
    version_added: 0.0.1
    version_added_collection: azure.azcollection

cert_validation_mode:
    choices:
    - ignore
    - validate
    description:
    - Controls the certificate validation behavior for Azure endpoints. By default, all
      modules will validate the server certificate, but when an HTTPS proxy is in use,
      or against Azure Stack, it may be necessary to disable this behavior by passing
      C(ignore). Can also be set via credential file profile or the C(AZURE_CERT_VALIDATION)
      environment variable.
    type: str
    version_added: 0.0.1
    version_added_collection: azure.azcollection

x509_certificate_path:
    description:
    - Path to the X509 certificate used to create the service principal in PEM format.
    - The certificate must be appended to the private key.
    - Use when authenticating with a Service Principal.
    type: path
    version_added: 1.14.0
    version_added_collection: azure.azcollection

disable_instance_discovery:
    default: false
    description:
    - Determines whether or not instance discovery is performed when attempting to authenticate.
      Setting this to true will completely disable both instance discovery and authority
      validation. This functionality is intended for use in scenarios where the metadata
      endpoint cannot be reached such as in private clouds or Azure Stack. The process
      of instance discovery entails retrieving authority metadata from https://login.microsoft.com/
      to validate the authority. By setting this to **True**, the validation of the authority
      is disabled. As a result, it is crucial to ensure that the configured authority
      host is valid and trustworthy.
    - Set via credential file profile or the C(AZURE_DISABLE_INSTANCE_DISCOVERY) environment
      variable.
    type: bool
    version_added: 2.3.0
    version_added_collection: azure.azcollection

Outputs

state:
  contains:
    event_hub:
      contains:
        hub:
          description:
          - Name of the hub within the namespace.
          returned: always
          sample: my-event-hub
          type: str
        id:
          description:
          - ID of the event hub namespace.
          returned: always
          sample: /subscriptions/xxx/resourceGroups/my-resource-group/providers/Microsoft.EventHub/namespaces/my-event-hub-namespace
          type: str
        namespace:
          description:
          - Name of the event hub namespace.
          returned: always
          sample: my-event-hub-namespace
          type: str
        policy:
          description:
          - Name of the event hub shared access policy.
          returned: always
          sample: RootManageSharedAccessKey
          type: str
      description:
      - The event hub for the diagnostic setting, if configured.
      returned: always
      type: dict
    id:
      description:
      - ID of the diagnostic setting.
      returned: always
      sample: /subscriptions/xxx/resourcegroups/my-resource-group/providers/microsoft.network/applicationgateways/my-appgw/
        providers/microsoft.insights/diagnosticSettings/my-diagnostic-setting
      type: str
    log_analytics:
      contains:
        id:
          description:
          - ID of the log analytics workspace.
          returned: always
          sample: /subscriptions/xxx/resourcegroups/my-resource-group/providers/microsoft.operationalinsights/workspaces/my-log-analytics-workspace
          type: str
      description:
      - The log analytics workspace for the diagnostic setting, if configured.
      returned: always
      type: dict
    logs:
      contains:
        category:
          description:
          - Name of a Management Group Diagnostic Log category for a resource type
            this setting is applied to.
          returned: always
          type: str
        category_group:
          description:
          - Name of a Management Group Diagnostic Log category group for a resource
            type this setting is applied to.
          returned: always
          type: str
        enabled:
          description:
          - Whether this log is enabled.
          returned: always
          type: bool
        retention_policy:
          contains:
            days:
              description:
              - The number of days for the retention policy.
              returned: always
              type: int
            enabled:
              description:
              - Whether the retention policy is enabled.
              returned: always
              type: bool
          description:
          - The retention policy for this log.
          returned: always
          type: dict
      description:
      - Enabled log configurations for the diagnostic setting.
      elements: dict
      returned: always
      type: list
    metrics:
      contains:
        category:
          description:
          - Name of a Diagnostic Metric category for a resource type this setting
            is applied to.
          returned: always
          type: str
        enabled:
          description:
          - Whether the metric category is enabled.
          returned: always
          type: bool
        retention_policy:
          contains:
            days:
              description:
              - The number of days for the retention policy.
              returned: always
              type: int
            enabled:
              description:
              - Whether the retention policy is enabled.
              returned: always
              type: bool
          description:
          - The retention policy for the metric category.
          returned: always
          type: dict
      description:
      - Enabled metric configurations for the diagnostic setting.
      elements: dict
      returned: always
      type: list
    name:
      description:
      - Name of the diagnostic setting.
      returned: always
      sample: my-diagnostic-setting
      type: str
    storage_account:
      contains:
        id:
          description:
          - ID of the storage account.
          returned: always
          sample: /subscriptions/xxx/resourceGroups/my-resource-group/providers/Microsoft.Storage/storageAccounts/my-storage-account
          type: str
      description:
      - The storage account for the diagnostic setting, if configured.
      returned: always
      type: dict
  description:
  - The state of the diagnostic setting.
  returned: always
  type: dict

See also