你好社区我正在运行以下ansible playbook
至azure cli
。
我从Ubuntu 18.04.4 LTS上也得到了类似的结果。
我也提出了一个github问题:https://github.com/Azure/Ansible/issues/21
使用Azure CLI是什么意思?
转到Azure:
->创建一个新的Cloud Shell
->已安装Ansible
->创建一个新的yml文件。复制以下脚本。
->运行以下剧本。使用此命令
ansible-playbook nameofyourfile.yml
->以下脚本失败
- hosts: localhost
connection: local
vars:
resource_group: ansibleResourceGroupName
webapp_name: ansibleWebAppName
plan_name: ansibleWebPlanName
location: westeurope
server_name: AnisbleDemoSqlServer
database_name: AnsibleDemoSqlDatabase
tasks:
- name: Create a resource group
azure_rm_resourcegroup:
name: "{{ resource_group }}"
location: "{{ location }}"
- name: Create App Service on Linux with dotnetcore
azure_rm_webapp:
resource_group: "{{ resource_group }}"
name: "{{ webapp_name }}"
plan:
resource_group: "{{ resource_group }}"
name: "{{ plan_name }}"
is_linux: true
sku: S1
number_of_workers: 1
frameworks:
- name: "dotnetcore"
version: "3.1"
- name: Create (or update) SQL Server
azure_rm_sqlserver:
resource_group: "{{ resource_group }}"
name: "{{ server_name }}"
location: "{{ location }}"
admin_username: panoskarajohn
admin_password: Testpasswordxyz12!
- name: Create (or update) SQL Database
azure_rm_sqldatabase:
resource_group: "{{ resource_group }}"
server_name: "{{ server_name }}"
name: "{{ database_name }}"
location: "{{ location }}"
- name: Create (or update) Firewall Rule
azure_rm_sqlfirewallrule:
resource_group: "{{ resource_group }}"
server_name: "{{ server_name }}"
name: firewallruleAllowAll
start_ip_address: 0.0.0.0.
end_ip_address: 255.255.255.255
我的sqlserver已创建。
但是防火墙规则失败,并带有 unauthorised error
。
At the end i have provided the errors
此外,当我尝试手动进行操作以通过天蓝色门户添加防火墙规则时。 一切均已停用。另外,添加客户端ip似乎无效。
即使允许我更改选择,保存按钮也无响应。 整个防火墙页面似乎没有响应。
查看图片以获取更多信息。
当我通过azure门户创建新的sql服务器时,一切似乎都可以运行。
感谢您的帮助。
我得到的错误:
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Error creating the Firewall Rule instance: 400 Client Error: Bad Request for url:
->一些网址。
当我点击网址时,我得到这个json-> {"error":{"code":"AuthenticationFailed","message":"Authentication failed. The 'Authorization' header is missing."}}
Ansible版本
可用2.9.6 配置文件=无 配置的模块搜索路径= [u'/ home / pkaragiannis / .ansible / plugins / modules',u'/ usr / share / ansible / plugins / modules'] ansible python模块位置= /usr/local/lib/python2.7/dist-packages/ansible 可执行位置= / usr / local / bin / ansible python版本= 2.7.17(默认,2019年11月7日,10:07:09)[GCC 7.4.0]
来自Ubuntu VM的Ansible输出
PLAY [localhost] *********************************************** ************************************************
任务[聚会事实] ********************************************** ******************************************* 好的:[localhost]
任务[创建资源组] ******************************************** ************************************** 更改为:[localhost]
任务[使用dotnetcore在Linux上创建应用程序服务] ***************************************** **************** 更改为:[localhost]
任务[创建(或更新)SQL Server] ***************************************** ****************************** [警告]:最新的Azure API配置文件未为SqlManagementClient定义条目 更改为:[localhost]
任务[创建(或更新)SQL数据库] ***************************************** **************************** 更改为:[localhost]
任务[创建(或更新)防火墙规则] ***************************************** **************************** 致命的:[本地主机]:失败! => {“更改”:false,“ msg”:“创建防火墙规则实例时出错:400客户端错误:错误的网址请求:https://management.azure.com/subscriptions/ ******-*****-** ***** / resourceGroups / ansibleResourceGroupName / providers / Microsoft.Sql / servers / AnisbleDemoSqlServer / firewallRules / firewallruleAllowAll?api-version = 2014-04-01“}
PLAY RECAP ********************************************* **************************************************** 本地主机:ok = 5更改= 4无法访问= 0失败= 1跳过= 0获救= 0忽略= 0
答案 0 :(得分:1)
当您要创建SQL Server及其防火墙规则时,我看到您使用服务主体进行身份验证。因此,首先,服务主体应具有您将使用的订阅或资源组的“贡献者”角色。
使用服务主体登录,然后使用Azure CLI命令创建SQL服务器和防火墙规则:
az sql server create -l westus -g mygroup -n myserver -u myadminuser -p myadminpassword
az sql server firewall-rule create -g mygroup -s myserver -n myrule --start-ip-address 1.2.3.4 --end-ip-address 5.6.7.8
使用Ansible,它也应该可以工作,并且我在代码中没有看到任何问题。只需使用服务主体正确设置凭据即可。
更新:
这是Ansible的屏幕截图:
Update-1:
这是上面截图的YAML文件:
- hosts: localhost
connection: local
tasks:
- name: Create (or update) SQL Server
azure_rm_sqlserver:
resource_group: mygroup
name: mysqlname
location: eastus
admin_username: username
admin_password: password
- name: Create (or update) Firewall Rule
azure_rm_sqlfirewallrule:
resource_group: mygroup
server_name: mysqlname
name: FirewallRule1
start_ip_address: 10.0.17.62
end_ip_address: 10.0.17.62