我试过以下的剧本,但它不起作用。不知道我在这里缺少什么。
hosts: localhost
connection: local
gather_facts: no
vars_files:
- vars/azure.yml
tasks:
- name: create VM
azure:
name: '{{ vm_name }}'
role_size: '{{ role_size }}'
image: '{{ image_name }}'
location: '{{ location }}'
user: '{{ username }}'
password: '{{ password }}'
subscription_id: '{{ subscription_id }}'
management_cert_path: '{{ certificate_path }}'
storage_account: '{{ storage_account_name }}'
virtual_network_name: '{{ virtual_network_name }}'
wait: yes
with_items:
- { name: "{{ vm_names_list }}" }
register : azure
- name : Debug Azure output
debug :
var : azure
我已经像我这样提到vm_names_list
:
vm_names_list:
- "loferVM123"
- "loferVM234"
它没有达到我的预期。我期望它创建三个VM。但它只创建一个VM。在调试输出中,它为我提供了列表中的项目,但只创建了一个VM。
这是调试输出:
"virtual_network_name": "myVirtualNetwork"
},
"invocation": {
"module_args": "",
"module_name": "azure"
},
"item": {
"vm_name": [
"loferVM123",
"loferVM234"
]
},
"public_dns_name": "lofervm175.cloudapp.net"
我的变量文件:
subscription_id: "ID"
certificate_path: "/path/to/certs/mycert.pem"
image_name: "5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-67-20150815"
storage_account_name: "mystorageacc"
virtual_network_name: "myVirtualNetwork"
username: "user"
password: "password"
vm_name: "lophani"
vm_names_list:
- "loferVM123"
- "loferVM234"
role_size: "Small"
location: "Central US"
data_disk_size: "100"
commitlog_disk_size: "10"
这是azure-cli vm show
的输出data: DNSName "lofervm234.cloudapp.net"
data: Location "Central US"
data: VMName "loferVM234"
data: IPAddress "10.0.2.6"
data: InstanceStatus "ReadyRole"
data: InstanceSize "Small"
data: Image "5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-67-20150815"
data: OSDisk hostCaching "ReadWrite"
data: OSDisk name "loferVM234-loferVM234-0-201510262116050841"
data: OSDisk mediaLink "http://portalvhdskswbj32fl5cx8.blob.core.windows.net/vhds/loferVM234-loferVM234-2015-10-26.vhd"
data: OSDisk sourceImageName "5112500ae3b842c8b9c604889f8753c3__OpenLogic-CentOS-67-20150815"
data: OSDisk operatingSystem "Linux"
data: OSDisk iOType "Standard"
data: DataDisks 0 hostCaching "None"
data: DataDisks 0 label "loferVM234-loferVM234-loferVM234-0"
data: DataDisks 0 name "loferVM234-loferVM234-0-201510262116380749"
data: DataDisks 0 logicalDiskSizeInGB 100
data: DataDisks 0 mediaLink "https://portalvhdskswbj32fl5cx8.blob.core.windows.net/vhds/loferVM234-b73613825dfb0bcb.vhd"
data: DataDisks 0 iOType "Standard"
data: DataDisks 1 hostCaching "None"
data: DataDisks 1 label "loferVM234-loferVM234-loferVM234-1"
data: DataDisks 1 name "loferVM234-loferVM234-1-201510262117180308"
data: DataDisks 1 logicalUnitNumber 1
data: DataDisks 1 logicalDiskSizeInGB 100
data: DataDisks 1 mediaLink "https://portalvhdskswbj32fl5cx8.blob.core.windows.net/vhds/loferVM234-cf18946abcbfe4c8.vhd"
data: DataDisks 1 iOType "Standard"
data: ReservedIPName ""
data: VirtualIPAddresses 0 address "104.43.202.234"
data: VirtualIPAddresses 0 name "loferVM234ContractContract"
data: VirtualIPAddresses 0 isDnsProgrammed true
data: Network Endpoints 0 localPort 22
data: Network Endpoints 0 name "TCP-22"
data: Network Endpoints 0 port 22
data: Network Endpoints 0 protocol "tcp"
data: Network Endpoints 0 virtualIPAddress "104.43.202.234"
data: Network Endpoints 0 enableDirectServerReturn false
data: Network Endpoints 0 idleTimeoutInMinutes 4