spot.cloud_modules.azure_stateful_node (1.3.3) — module

Create, update, Import or delete Spot Azure Stateful Nodes

| "added in version" 1.1.0 of spot.cloud_modules"

Authors: Spot by NetApp (@anuragsharma-123)

Install collection

Install with ansible-galaxy collection install spot.cloud_modules:==1.3.3


Add to requirements.yml

  collections:
    - name: spot.cloud_modules
      version: 1.3.3

Description

Create, update, delete, import or perform actions (pause, resume, recycle) on Spot Azure Stateful Nodes. You will have to have a credentials file in this location - <home>/.spotinst/credentials The credentials file must contain a row that looks like this token = <YOUR TOKEN> Full documentation available at [our docs site](https://docs.spot.io/)


Requirements

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Basic Example
- hosts: localhost
  tasks:
    - name: stateful_node
      spot.cloud_modules.azure_stateful_node:
        state: present
        uniqueness_by: "id"
        do_not_update:
          - region
          - resource_group_name
        stateful_node:
          name: "ansible-stateful-node-example"
          description: "a sample Stateful Node created via Ansible"
          region: "eastus"
          resource_group_name: "AutomationResourceGroup"
          persistence:
            data_disks_persistence_mode: "reattach"
            os_disk_persistence_mode: "reattach"
            should_persist_data_disks: true
            should_persist_network: true
            should_persist_os_disk: true
          health:
            health_check_types: ["vmState"]
            auto_healing: true
            grace_period: 300
            unhealthy_duration: 120
          strategy:
            draining_timeout: 300
            fallback_to_od: true
            preferred_lifecycle: "spot"
            revert_to_spot:
              perform_at: "always"
          compute:
            os: "Linux"
            zones: ["1", "2"]
            preferred_zone: "2"
            vm_sizes:
              od_sizes: ["standard_a1_v2", "standard_a2_v2"]
              spot_sizes: ["standard_a1_v2", "standard_a2_v2"]
              preferred_spot_sizes: ["standard_a1_v2"]
            launch_specification:
              data_disks:
                - lun: 0
                  size_g_b: 30
                  type: "Standard_LRS"
              image:
                marketplace:
                  publisher: "Canonical"
                  version: "latest"
                  sku: "18.04-LTS"
                  offer: "UbuntuServer"
              login:
                user_name: "ubuntu"
                ssh_public_key: <add-your-ssh-key-here>
              network:
                resource_group_name: "AutomationResourceGroup"
                virtual_network_name: "Automation-VirtualNetwork"
                network_interfaces:
                  - is_primary: true
                    assign_public_ip: true
                    public_ip_sku: "Standard"
                    subnet_name: "Automation-PrivateSubnet"
                    enable_ip_forwarding: true
              os_disk:
                size_g_b: 30
                type: "Standard_LRS"
              tags:
                - tag_key: "Creator"
                  tag_value: "Ansible Test"
                - tag_key: "Name"
                  tag_value: "Ansible Basic Example"
      register: result
    - debug: var=result

Inputs

    
id:
    description:
    - The Stateful Node ID if it already exists and you want to update or delete it.
    - This will have no effect unless the `uniqueness_by` field is set to ID.
    - When this is set, and the `uniqueness_by` field is set, the node will either be
      updated or deleted, but not created.
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description: create update or delete
    type: str

token:
    description:
    - Optional parameter that allows to set an token inside the module configuration.
      By default this is retrieved from the credentials path
    type: str

vm_id:
    description:
    - When state is `present` and vm_id is set, the VM defined in `import_vm_config` specification
      will be imported.
    type: str

action:
    choices:
    - pause
    - resume
    - recycle
    description:
    - Perform the desired action on the azure stateful node. This has no effect on delete
      operations.
    type: str

account_id:
    description:
    - Optional parameter that allows to set an account-id inside the module configuration.
      By default this is retrieved from the credentials path
    type: str

do_not_update:
    description:
    - A list of dotted paths to attributes that you don't wish to update during an update
      operation.
    - 'Example: Specifying `compute.product` will make sure that this attribute is never
      updated.'
    elements: str
    type: list

stateful_node:
    description: Describe the desired properties of the stateful node under this object.
    suboptions:
      compute:
        description: Defines the computational parameters to use when launch the VM for
          the Stateful Node.
        suboptions:
          launch_specification:
            description: Defines the launch specification of the VM.
            suboptions:
              boot_diagnostics:
                description: Will enable boot diagnostics in Azure when a new VM is launched
                suboptions:
                  is_enabled:
                    description: Allows you to enable and disable the configuration of
                      boot diagnostics at launch
                    required: true
                    type: bool
                  storage_uri:
                    description: The storage URI that is used if a type is unmanaged.
                    type: str
                  type:
                    description: 'Defines the storage type on VM launch in Azure. Valid
                      Values: `managed`, `unmanaged`'
                    required: true
                    type: str
                type: dict
              custom_data:
                description: Defines the custom data (YAML encoded at Base64) that will
                  be executed upon VM launch.
                type: str
              data_disks:
                description: The definitions of data disks that will be created and attached
                  to the stateful node's VM.
                elements: dict
                suboptions:
                  lun:
                    description: The LUN of the data disk.
                    required: true
                    type: int
                  size_g_b:
                    description: The size of the data disk in GB, required if dataDisks
                      is specified.
                    required: true
                    type: int
                  type:
                    description: 'Type of data disk. Valid Values: `Standard_LRS`, `Premium_LRS`,
                      `StandardSSD_LRS`, `UltraSSD_LRS`'
                    required: true
                    type: str
                type: list
              extensions:
                description: A list of objects for Azure extensions.
                elements: dict
                suboptions:
                  api_version:
                    description: The API version of the extension. Required if extension
                      specified.
                    required: true
                    type: str
                  minor_version_auto_upgrade:
                    description: Required on compute.launchSpecification.extensions object
                    required: true
                    type: bool
                  name:
                    description: Required on compute.launchSpecification.extensions object
                    required: true
                    type: str
                  publisher:
                    description: Required on compute.launchSpecification.extensions object
                    required: true
                    type: str
                  type:
                    description: Required on compute.launchSpecification.extensions object
                    required: true
                    type: str
                type: list
              image:
                description: Defines the image with which the VM will be launched.
                suboptions:
                  custom:
                    description: Custom image definitions.
                    suboptions:
                      name:
                        description: The name of the custom image.
                        required: true
                        type: str
                      resource_group_name:
                        description: The resource group name for custom image.
                        required: true
                        type: str
                    type: dict
                  gallery:
                    description: Gallery image definitions.
                    suboptions:
                      gallery_name:
                        description: Name of the gallery.
                        required: true
                        type: str
                      image_name:
                        description: Name of the gallery image.
                        required: true
                        type: str
                      resource_group_name:
                        description: The resource group name for gallery image.
                        required: true
                        type: str
                      spot_account_id:
                        description: The Spot account ID that connected to the Azure subscription
                          to which the gallery belongs.
                        type: str
                      version_name:
                        description: Image's version. Can be in the format x.x.x or 'latest'.
                        required: true
                        type: str
                    type: dict
                  marketplace:
                    description: Select an image from Azure's Marketplace image catalogue.
                    suboptions:
                      offer:
                        description: Image offer.
                        required: true
                        type: str
                      publisher:
                        description: Image publisher.
                        required: true
                        type: str
                      sku:
                        description: Image Stock Keeping Unit, which is the specific version
                          of the image.
                        required: true
                        type: str
                      version:
                        description: 'Image Version. Default: `latest`'
                        required: true
                        type: str
                    type: dict
                type: dict
              license_type:
                description:
                - Specify an existing Azure license type to use when launching new VMs.
                - 'Valid values for Windows OS: `Windows_Server`, `Windows_Client`'
                - 'Valid values for Linux OS: `RHEL_BYOS`, `SLES_BYOS`'
                type: str
              load_balancers_config:
                description: Configure a Load Balancer.
                suboptions:
                  load_balancers:
                    description: Add a load balancer. For Azure Gateway, each Backend
                      Pool is a separate load balancer.
                    elements: dict
                    suboptions:
                      backend_pool_names:
                        description: Name of the Backend Pool to register the Stateful
                          Node VMs to.
                        elements: str
                        required: true
                        type: list
                      load_balancer_sku:
                        description:
                        - 'if type is LoadBalancer then Valid Values are: `Standard`,
                          `Basic`'
                        - 'if ApplicationGateway then Valid Values are: `Standard_Large`,
                          `Standard_Medium`, `Standard_Small`, `Standard_v2`, `WAF_v2`,
                          `WAF_Large`, `WAF_Medium`'
                        type: str
                      name:
                        description: Name of the Application Gateway/Load Balancer
                        required: true
                        type: str
                      resource_group_name:
                        description: The Resource Group name of the Load Balancer.
                        required: true
                        type: str
                      type:
                        description: 'The type of load balancer. Valid Values: `loadBalancer`,
                          `applicationGateway`'
                        required: true
                        type: str
                    type: list
                type: dict
              login:
                description: Specify the authentication details to be used for launching
                  VMs.
                suboptions:
                  password:
                    description: Defines the password for admin access to Windows VMs.
                    type: str
                  ssh_public_key:
                    description: Defines the SSH public key for admin access to Linux
                      VMs.
                    type: str
                  user_name:
                    description: Defines the admin user name for launching VMs.
                    required: true
                    type: str
                type: dict
              managed_service_identities:
                description: Defines a user-assigned managed identity to the launched
                  VMs.
                elements: dict
                suboptions:
                  name:
                    description: Defines the name of the managed service identities.
                    required: true
                    type: str
                  resource_group_name:
                    description: Defines the resource group of the managed service identities.
                    required: true
                    type: str
                type: list
              network:
                description: Defines the network profile with which the VM will be launched.
                suboptions:
                  network_interfaces:
                    description: Defines the network interfaces with which the VM will
                      be launched.
                    elements: dict
                    required: true
                    suboptions:
                      additional_ip_configurations:
                        description: Defines a list of extra IPs to be dynamically allocated.
                        elements: dict
                        suboptions:
                          name:
                            description: The name of the additional Ip Configuration.
                            required: true
                            type: str
                          private_ip_address_version:
                            description: 'Defines the version of the private IP address.
                              Valid Values: `IPv4`, `IPv6`'
                            required: true
                            type: str
                        type: list
                      application_security_groups:
                        description:
                        - Defines the Application Security Groups that will be associated
                          to the primary IP configration of the network interface.
                        elements: dict
                        suboptions:
                          name:
                            description: Specify the name of the Application Security
                              Group.
                            required: true
                            type: str
                          resource_group_name:
                            description: Specify the resource group of the Application
                              Security Group.
                            required: true
                            type: str
                        type: list
                      assign_public_ip:
                        description: Defines if a Public IP should be assigned in this
                          network interface.
                        type: bool
                      enable_ip_forwarding:
                        description: Enables IP forwarding on the network interface.
                        type: bool
                      is_primary:
                        description: Defines whether the network interface is primary
                          or not.
                        required: true
                        type: bool
                      network_security_group:
                        description: Defines the network security group to which the network
                          interface will be assigned.
                        suboptions:
                          name:
                            description: Specify the name of the network security group
                              to use in this network interface.
                            required: true
                            type: str
                          resource_group_name:
                            description: Specify the resource group of the network security
                              group.
                            required: true
                            type: str
                        type: dict
                      private_ip_addresses:
                        description: Specify the private IP pool in which the VMs will
                          be launched.
                        elements: str
                        type: list
                      public_ip_sku:
                        description: 'Defines the type of public IP to assign the VM.
                          Valid Values: `Standard`, `Basic`'
                        type: str
                      public_ips:
                        description: Specify the public IP pool in which the VMs will
                          be launched.
                        elements: dict
                        suboptions:
                          name:
                            description: Specify the name of the public IP to which the
                              VMs will be assigned.
                            required: true
                            type: str
                          resource_group_name:
                            description: Specify the resource group of the public IP.
                            required: true
                            type: str
                        type: list
                      subnet_name:
                        description: Defines the subnet to which the network interface
                          will be connected.
                        required: true
                        type: str
                    type: list
                  resource_group_name:
                    description: Defines the resource group name of the virtual network
                      with which the VM will be launched.
                    required: true
                    type: str
                  virtual_network_name:
                    description: Defines the name of the virtual network with which the
                      VM will be launched.
                    required: true
                    type: str
                type: dict
              os_disk:
                description: Specify OS disk specification other than default.
                suboptions:
                  size_g_b:
                    description: The size of the OS disk in GB.
                    type: int
                  type:
                    description: 'Type of OS disk. Valid Values: `Standard_LRS`, `Premium_LRS`,
                      `StandardSSD_LRS`'
                    required: true
                    type: str
                type: dict
              proximity_placement_groups:
                description: Defines the proximity placement group in which the VM will
                  be launched.
                elements: dict
                suboptions:
                  name:
                    description: The name of the proximity placement group.
                    required: true
                    type: str
                  resource_group_name:
                    description: The resource group name of the proximity placement group.
                    required: true
                    type: str
                type: list
              secrets:
                description: Set of certificates that should be installed on the VM
                elements: dict
                suboptions:
                  source_vault:
                    description: The key vault reference, contains the required certificates
                    required: true
                    suboptions:
                      name:
                        description: The name of the key vault
                        required: true
                        type: str
                      resource_group_name:
                        description: The resource group name of the key vault
                        required: true
                        type: str
                    type: dict
                  vault_certificates:
                    description: The required certificate references
                    elements: dict
                    required: true
                    suboptions:
                      certificate_store:
                        description: The certificate store directory the VM.
                        required: true
                        type: str
                      certificate_url:
                        description: The URL of the certificate under the key vault
                        required: true
                        type: str
                    type: list
                type: list
              security:
                description: Specifies the Security related profile settings for the virtual
                  machine.
                suboptions:
                  secure_boot_enabled:
                    description: Specifies whether secure boot should be enabled on the
                      virtual machine.
                    type: bool
                  security_type:
                    description: 'Refers to the different security features of a VM. Valid
                      values: `Standard`, `TrustedLaunch`.'
                    type: str
                  v_tpm_enabled:
                    description: Specifies whether vTPM should be enabled on the virtual
                      machine.
                    type: bool
                type: dict
              shutdown_script:
                description: Defines the shutdown script (encoded at Base64) to execute
                  once the VM is detached.
                type: str
              tags:
                description: Defines the tags (unique key-value pairs) to tag your resources.
                elements: dict
                suboptions:
                  tag_key:
                    description: Tag key for all resources.
                    type: str
                  tag_value:
                    description: Tag value for all resources.
                    type: str
                type: list
              user_data:
                description: Set of scripts or other metadata that's inserted to an Azure
                  VM at provision time. (Base64 encoded)
                type: str
              vm_name:
                description: Set a VM name that will be persisted throughout the entire
                  node lifecycle.
                type: str
              vm_name_prefix:
                description: Set a VM name prefix to be used for all launched VMs and
                  the VM resources.
                type: str
            type: dict
          os:
            description: 'Defines the type of the operating system. Valid Values: `Linux`,
              `Windows`'
            type: str
          preferred_zone:
            description: 'The AZ to prioritize when launching VMs. Valid Values: `1`,
              `2`, `3`'
            type: str
          vm_sizes:
            description: Defines the VM sizes to use when launching VMs.
            required: true
            suboptions:
              od_sizes:
                description: Defines the on-demand sizes to use when launching VMs.
                elements: str
                required: true
                type: list
              preferred_spot_sizes:
                description: Prioritize Spot VM sizes when launching Spot VMs.
                elements: str
                type: list
              spot_sizes:
                description: Defines the spot-VM sizes to use when launching VMs.
                elements: str
                required: true
                type: list
            type: dict
          zones:
            description: 'List of Azure Availability Zones in the defined region. Valid
              Values: `1`, `2`, `3`'
            elements: str
            type: list
        type: dict
      description:
        description: optional description for the stateful node.
        type: str
      health:
        description: Set health check and auto-healing of unhealthy VMs.
        suboptions:
          auto_healing:
            description: Auto healing replaces the instance automatically in case the
              health check fails
            type: bool
          grace_period:
            description: The amount of time (in seconds) after a new VM has launched before
              terminating the old VM.
            type: int
          health_check_types:
            description: 'Health check types to use in order to validate VM health. valid
              values: `vmState`, `applicationGateway`'
            elements: str
            type: list
          unhealthy_duration:
            description: Amount of time (in seconds) for the VM to remain unhealthy before
              a replacement is triggered.
            type: int
        type: dict
      name:
        description: The stateful node's name.
        type: str
      persistence:
        description: Defines the persistence of the Stateful Node.
        suboptions:
          data_disks_persistence_mode:
            description: 'Defines the persistency handling for data disks. valid values:
              `reattach`, `onLaunch`'
            type: str
          os_disk_persistence_mode:
            description: 'Defines the persistency handling for os disk. valid values:
              `reattach`, `onLaunch`'
            type: str
          should_persist_data_disks:
            description: Enables the data disks persistency.
            required: true
            type: bool
          should_persist_network:
            description: Enables the network persistency.
            required: true
            type: bool
          should_persist_os_disk:
            description: Enables the OS disk persistency.
            required: true
            type: bool
        type: dict
      region:
        description: The Azure region in which the Stateful Node will be launched.
        type: str
      resource_group_name:
        description: The Azure resource group in which the VM and all of the subsequent
          subresources will be launched.
        type: str
      scheduling:
        description: Scheduling settings for stateful node
        suboptions:
          tasks:
            description: Scheduled tasks to excute for the stateful node
            elements: dict
            suboptions:
              cron_expression:
                description: A valid cron expression that describes the scheduled task
                  (UTC).
                required: true
                type: str
              is_enabled:
                description: Describes whether the task is enabled. When true the task
                  should run when false it should not run.
                required: true
                type: bool
              type:
                description: 'The type of scheduled task. valid values: `pause`, `resume`,
                  `recycle`'
                required: true
                type: str
            type: list
        type: dict
      strategy:
        description: The strategy to launch the underlying VM and Spot behavior for the
          Stateful Node.
        suboptions:
          availability_vs_cost:
            description: Set the desired preference for the Spot market VM selection.
              (100 - Availability, 0 - cost).
            type: int
          capacity_reservation:
            description: Reserve Compute capacity in an Azure region or an Availability
              Zone for any duration of time.
            suboptions:
              capacity_reservation_groups:
                description: List of the desired CRGs to use under the associated Azure
                  subscription.
                elements: dict
                suboptions:
                  name:
                    description: The name of the CRG.
                    required: true
                    type: str
                  resource_group_name:
                    description: Azure resource group name.
                    required: true
                    type: str
                  should_prioritize:
                    description: The desired CRG to utilize ahead of other CRGs in the
                      subscription.
                    type: bool
                type: list
              should_utilize:
                description: Determines whether capacity reservations should be utilized.
                required: true
                type: bool
              utilization_strategy:
                description: 'The priority requested for using CRG. Valid values: `utilizeOverSpot`,
                  `utilizeOverOD`'
                required: true
                type: str
            type: dict
          draining_timeout:
            description: 'The time in seconds to allow the node be drained from incoming
              TCP connections and detached from LB before terminating it. Default: 120.'
            type: int
          fallback_to_od:
            description: In case of no spots available, stateful node will launch an On-demand
              instance instead
            required: true
            type: bool
          od_windows:
            description: Define the time windows in which the underlying VM will be set
              as an on-demand lifecycle type.
            elements: str
            type: list
          optimization_windows:
            description: 'When performAt is `timeWindow`: must specify a list of `timeWindows`
              with at least one time window Each string is in theformat of - `ddd:hh:mm-ddd:hh:mm
              ddd` = day of week = Sun | Mon | Tue | Wed | Thu | Fri | Sat hh = hour 24
              = 0 - 23 mm = minute = 0 - 59'
            elements: str
            type: list
          preferred_lifecycle:
            description: 'The preferred lifecycle to launch VM, valid values: `spot`,
              `od`. Default: `spot`'
            type: str
          revert_to_spot:
            description: Hold settings for strategy correction - replacing On-Demand for
              Spot VMs.
            suboptions:
              perform_at:
                description: 'Valid values: `always`, `never`, `timeWindow`. Default:
                  `always`'
                required: true
                type: str
            type: dict
          signals:
            description: Signals that VMs are expected to send to the platform.
            elements: dict
            suboptions:
              timeout:
                description: 'The timeout in seconds to hold the vm until a signal is
                  sent. Default: 1800'
                required: true
                type: int
              type:
                description: 'The defined type of signal. Valid values: `vmReady`, `vmReadyToShutdown`'
                required: true
                type: str
            type: list
        type: dict
    type: dict

uniqueness_by:
    choices:
    - id
    - name
    description:
    - If your Stateful Node names are not unique, you may use this feature to update or
      delete a specific node.
    - Whenever this property is set, you must set a an `id` in order to update or delete
      a node, otherwise a node will be created.
    type: str

credentials_path:
    default: /root/.spotinst/credentials
    description: Optional parameter that allows to set a non-default credentials path.
    type: str

stateful_node_config:
    description: Various configurations related to the stateful node
    suboptions:
      deletion_config:
        description: Configurations related to the deletion of the stateful node
        suboptions:
          deallocation_config:
            description: Deletion configuration for each stateful node's resources
            suboptions:
              disk_deallocation_config:
                description: Disk Deallocation Configuration.
                suboptions:
                  should_deallocate:
                    description: Indicates whether to delete the stateful node's disk
                      resources.
                    required: true
                    type: bool
                  ttl_in_hours:
                    description: 'Hours to keep the resource alive before deletion. Default:
                      96'
                    type: int
                type: dict
              network_deallocation_config:
                description: Network Deallocation Configuration.
                suboptions:
                  should_deallocate:
                    description: Indicates whether to delete the stateful node's network
                      resources.
                    required: true
                    type: bool
                  ttl_in_hours:
                    description: 'Hours to keep the resource alive before deletion. Default:
                      96'
                    type: int
                type: dict
              public_ip_deallocation_config:
                description: Public IP Deallocation Configuration.
                suboptions:
                  should_deallocate:
                    description: Indicates whether to delete the stateful node's public
                      ip resources.
                    required: true
                    type: bool
                  ttl_in_hours:
                    description: 'Hours to keep the resource alive before deletion. Default:
                      96'
                    type: int
                type: dict
              should_terminate_vm:
                description: Indicates whether to delete the stateful node's VM.
                required: true
                type: bool
              snapshot_deallocation_config:
                description:
                - Snapshot Deallocation Configuration.
                suboptions:
                  should_deallocate:
                    description: Indicates whether to delete the stateful node's snapshot
                      resources.
                    required: true
                    type: bool
                  ttl_in_hours:
                    description: 'Hours to keep the resource alive before deletion. Default:
                      96'
                    type: int
                type: dict
            type: dict
        type: dict
      import_vm_config:
        description: Configurations for importing a VM to a stateful node
        suboptions:
          convert_unmanaged_disks:
            description: Converts virtual machine unmanaged disks to managed disks.
            type: bool
          draining_timeout:
            description: Time in seconds before shutdown incase of load balancing.
            type: int
          original_vm_name:
            description: Azure Import Stateful Node Name.
            required: true
            type: str
          resource_group_name:
            description: Name of the Resource Group for Stateful Node.
            required: true
            type: str
          resource_retention_time:
            description: Time in hours to delete the original resources after the import
              has finished
            type: int
        type: dict
    type: dict

Outputs

stateful_node_id:
  description: The ID of the stateful node that was just created/update/deleted.
  returned: success
  sample: ssn-792f7f87
  type: str