【问题标题】:How to deploy Azure SQL S0 instance with ansible azure_rm_sqldatabase?如何使用 ansible azure_rm_sqldatabase 部署 Azure SQL S0 实例?
【发布时间】:2019-10-28 20:38:23
【问题描述】:

本周或上周,MS 更改了 Azure DB 默认部署设置。 我们的部署脚本开始创建通用 2 vcores 实例而不是 S0 实例。我正在尝试修复它,但看起来要么文档不正确,要么我做错了什么。

我们的初始脚本是:

  azure_rm_sqldatabase:
    resource_group: "{{ resource_group }}"
    server_name: "{{ db_server }}"
    name: "{{ item }}"
    location: "{{ location }}"
  with_items:
    - "{{ database_list }}"
  register: async_result
  async: 7200
  poll: 0

根据文档,它应该可以通过添加 2 个参数来解决。

  1. 版本:标准

  2. max_size_bytes:268435456000

但事实证明这还不够。

我尝试使用 create_mode 或减少 max_size_bytes 但没有运气。

- name: Create SQL Database for "{{ stack_name }}"
  azure_rm_sqldatabase:
    resource_group: "{{ resource_group }}"
    server_name: "{{ db_server }}"
    name: "{{ item }}"
    location: "{{ location }}"
    create_mode: default
    edition: standard
    max_size_bytes: 268435456000‬ 

在所有情况下我都会遇到错误:

failed: [127.0.0.1] (item={'_ansible_parsed': True, '_ansible_item_result': True, '_ansible_item_label': u'authentication', 
u'ansible_job_id': u'701489864709.12193', 'failed': False, u'started': 1, 'changed': True, 'item': u'authentication', u'finished': 0, 
u'results_file': u'/home/vb/.ansible_async/701489864709.12193', '_ansible_ignore_errors': None, '_ansible_no_log': False}) => 
{"ansible_job_id": "701489864709.12193", "attempts": 2, "changed": false, "finished": 1, 
"item": {"ansible_job_id": "701489864709.12193", "changed": true, "failed": false, "finished": 0, "item": "authentication", 
"results_file": "/home/vb/.ansible_async/701489864709.12193", "started": 1}, "msg": 
"Error creating the SQL Database instance: 400 Client Error: 
Bad Request for url: https://management.azure.com/subscriptions/1bbba5c5-fbdb-18d7-8128-b4d403d7c6c5/resourceGroups/test_rg/providers/Microsoft.Sql/servers/testserver/databases/authentication?api-version=2014-04-01"}

请让我知道我做错了什么。

更新: 将 ansible 升级到最新版本后,我遇到了另一个错误:

DeserializationError: Unable to deserialize response data. Data: 268435456000‬, long, ValueError: invalid literal for long() with base 10: '268435456000\\xe2\\x80\\xac'"

我减小了 db 大小,创建了数据库,但是它不是 S0,而是创建为 2vcore。

【问题讨论】:

    标签: ansible azure-sql-database


    【解决方案1】:

    我能够使用azure_rm_resource 任务创建 S0 实例。通过这项任务,您基本上可以完成 azure api 提供的所有操作。

    这里是创建databases的API操作。

    根据您的初始脚本,它应该变成:

    azure_rm_resource:
      resource_group: "{{ resource_group }}"
      resource_name: "{{ db_server }}"
      provider: SQL
      resource_type: servers
      subresource:
        - type: databases
          name: "{{item}}"
      body:
        location: "{{ location }}"
        sku:
          tier: "Standard"
          name: "S0"
          capacity: 10
        properties:
          maxSizeBytes: 2147483648
    with_items:
      - "{{ database_list }}"
    register: async_result
    async: 7200
    poll: 0
    

    【讨论】:

      【解决方案2】:

      我无法使用 azure_rm_sqldatabase 解决问题,所以我不得不使用 bash 命令解决它。如果我能找到更好的解决方案,我会更新这个答案。 如果有人会遇到同样的问题,这里是示例代码:

      - name: Create SQL Database for "{{ stack_name }}"
        command: bash -c "az sql db create --name {{ item }} --resource-group {{ resource_group }} --server {{ db_server }} --capacity 10 --edition Standard --service-objective S0"  
        with_items:
          - "{{ database_list }}"
        register: async_result
        async: 7200
        poll: 0
      

      【讨论】:

        【解决方案3】:

        和你一样,我们也经历过。在我的情况下:azure sql server 数据库的默认创建使用通用 4 计算(这真的很昂贵)。根据我的经验,我们使用 t-sql 代码创建数据库:

        CREATE DATABASE 'dbName'
        

        这会在 azure 中创建昂贵的 gen4 计算。所以我搜索了一些文档,根据t-sql azure create database 的文档,它具有创建特定定价层的参数:SERVICE_OBJECTIVE,例如,对于 S2 计算,我们现在使用以下 t-sql:

        CREATE DATABASE 'dbName' ( EDITION = 'standard', SERVICE_OBJECTIVE = 'S2' ) ;
        

        这对我们有用。虽然,我不知道如何从脚本或命令行调用这些参数,但应该可以发送SERVICE_OBJECTIVE,因为这可能是缺少的键。

        【讨论】:

          猜你喜欢
          • 2020-08-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多