mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
enable the module to provision windows instances
This commit is contained in:
parent
97a2cd0bd9
commit
2314670952
1 changed files with 74 additions and 7 deletions
|
@ -110,6 +110,34 @@ options:
|
||||||
required: false
|
required: false
|
||||||
default: 'present'
|
default: 'present'
|
||||||
aliases: []
|
aliases: []
|
||||||
|
reset_pass_atlogon:
|
||||||
|
description:
|
||||||
|
- Reset the admin password on first logon for windows hosts
|
||||||
|
required: false
|
||||||
|
default: "no"
|
||||||
|
version_added: "2.0"
|
||||||
|
choices: [ "yes", "no" ]
|
||||||
|
auto_updates:
|
||||||
|
description:
|
||||||
|
- Enable Auto Updates on Windows Machines
|
||||||
|
required: false
|
||||||
|
version_added: "2.0"
|
||||||
|
default: "no"
|
||||||
|
choices: [ "yes", "no" ]
|
||||||
|
enable_winrm:
|
||||||
|
description:
|
||||||
|
- Enable winrm on Windows Machines
|
||||||
|
required: false
|
||||||
|
version_added: "2.0"
|
||||||
|
default: "yes"
|
||||||
|
choices: [ "yes", "no" ]
|
||||||
|
os_type:
|
||||||
|
description:
|
||||||
|
- The type of the os that is gettings provisioned
|
||||||
|
required: false
|
||||||
|
version_added: "2.0"
|
||||||
|
default: "linux"
|
||||||
|
choices: [ "windows", "linux" ]
|
||||||
|
|
||||||
requirements:
|
requirements:
|
||||||
- "python >= 2.6"
|
- "python >= 2.6"
|
||||||
|
@ -138,6 +166,29 @@ EXAMPLES = '''
|
||||||
module: azure
|
module: azure
|
||||||
name: my-virtual-machine
|
name: my-virtual-machine
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
|
#Create windows machine
|
||||||
|
- hosts: all
|
||||||
|
connection: local
|
||||||
|
tasks:
|
||||||
|
- local_action:
|
||||||
|
module: azure
|
||||||
|
name: "ben-Winows-23"
|
||||||
|
hostname: "win123"
|
||||||
|
os_type: windows
|
||||||
|
enable_winrm: yes
|
||||||
|
subscription_id: "{{ azure_sub_id }}"
|
||||||
|
management_cert_path: "{{ azure_cert_path }}"
|
||||||
|
role_size: Small
|
||||||
|
image: 'bd507d3a70934695bc2128e3e5a255ba__RightImage-Windows-2012-x64-v13.5'
|
||||||
|
location: 'East Asia'
|
||||||
|
password: "xxx"
|
||||||
|
storage_account: benooytes
|
||||||
|
user: admin
|
||||||
|
wait: yes
|
||||||
|
virtual_network_name: "{{ vnet_name }}"
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
@ -196,7 +247,7 @@ try:
|
||||||
from azure import WindowsAzureError, WindowsAzureMissingResourceError
|
from azure import WindowsAzureError, WindowsAzureMissingResourceError
|
||||||
from azure.servicemanagement import (ServiceManagementService, OSVirtualHardDisk, SSH, PublicKeys,
|
from azure.servicemanagement import (ServiceManagementService, OSVirtualHardDisk, SSH, PublicKeys,
|
||||||
PublicKey, LinuxConfigurationSet, ConfigurationSetInputEndpoints,
|
PublicKey, LinuxConfigurationSet, ConfigurationSetInputEndpoints,
|
||||||
ConfigurationSetInputEndpoint)
|
ConfigurationSetInputEndpoint, Listener, WindowsConfigurationSet)
|
||||||
HAS_AZURE = True
|
HAS_AZURE = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_AZURE = False
|
HAS_AZURE = False
|
||||||
|
@ -264,6 +315,7 @@ def create_virtual_machine(module, azure):
|
||||||
True if a new virtual machine and/or cloud service was created, false otherwise
|
True if a new virtual machine and/or cloud service was created, false otherwise
|
||||||
"""
|
"""
|
||||||
name = module.params.get('name')
|
name = module.params.get('name')
|
||||||
|
os_type = module.params.get('os_type')
|
||||||
hostname = module.params.get('hostname') or name + ".cloudapp.net"
|
hostname = module.params.get('hostname') or name + ".cloudapp.net"
|
||||||
endpoints = module.params.get('endpoints').split(',')
|
endpoints = module.params.get('endpoints').split(',')
|
||||||
ssh_cert_path = module.params.get('ssh_cert_path')
|
ssh_cert_path = module.params.get('ssh_cert_path')
|
||||||
|
@ -296,9 +348,20 @@ def create_virtual_machine(module, azure):
|
||||||
except WindowsAzureMissingResourceError:
|
except WindowsAzureMissingResourceError:
|
||||||
# vm does not exist; create it
|
# vm does not exist; create it
|
||||||
|
|
||||||
# Create linux configuration
|
if os_type == 'linux':
|
||||||
disable_ssh_password_authentication = not password
|
# Create linux configuration
|
||||||
linux_config = LinuxConfigurationSet(hostname, user, password, disable_ssh_password_authentication)
|
disable_ssh_password_authentication = not password
|
||||||
|
vm_config = LinuxConfigurationSet(hostname, user, password, disable_ssh_password_authentication)
|
||||||
|
else:
|
||||||
|
#Create Windows Config
|
||||||
|
vm_config = WindowsConfigurationSet(hostname, password, module.params.get('reset_pass_atlogon'),\
|
||||||
|
module.params.get('auto_updates'), None, user)
|
||||||
|
vm_config.domain_join = None
|
||||||
|
if module.params.get('enable_winrm'):
|
||||||
|
listener = Listener('Http')
|
||||||
|
vm_config.win_rm.listeners.listeners.append(listener)
|
||||||
|
else:
|
||||||
|
vm_config.win_rm = None
|
||||||
|
|
||||||
# Add ssh certificates if specified
|
# Add ssh certificates if specified
|
||||||
if ssh_cert_path:
|
if ssh_cert_path:
|
||||||
|
@ -340,7 +403,7 @@ def create_virtual_machine(module, azure):
|
||||||
deployment_slot='production',
|
deployment_slot='production',
|
||||||
label=name,
|
label=name,
|
||||||
role_name=name,
|
role_name=name,
|
||||||
system_config=linux_config,
|
system_config=vm_config,
|
||||||
network_config=network_config,
|
network_config=network_config,
|
||||||
os_virtual_hard_disk=os_hd,
|
os_virtual_hard_disk=os_hd,
|
||||||
role_size=role_size,
|
role_size=role_size,
|
||||||
|
@ -448,6 +511,7 @@ def main():
|
||||||
ssh_cert_path=dict(),
|
ssh_cert_path=dict(),
|
||||||
name=dict(),
|
name=dict(),
|
||||||
hostname=dict(),
|
hostname=dict(),
|
||||||
|
os_type=dict(default='linux', choices=['linux', 'windows']),
|
||||||
location=dict(choices=AZURE_LOCATIONS),
|
location=dict(choices=AZURE_LOCATIONS),
|
||||||
role_size=dict(choices=AZURE_ROLE_SIZES),
|
role_size=dict(choices=AZURE_ROLE_SIZES),
|
||||||
subscription_id=dict(no_log=True),
|
subscription_id=dict(no_log=True),
|
||||||
|
@ -461,7 +525,10 @@ def main():
|
||||||
state=dict(default='present'),
|
state=dict(default='present'),
|
||||||
wait=dict(type='bool', default=False),
|
wait=dict(type='bool', default=False),
|
||||||
wait_timeout=dict(default=600),
|
wait_timeout=dict(default=600),
|
||||||
wait_timeout_redirects=dict(default=300)
|
wait_timeout_redirects=dict(default=300),
|
||||||
|
reset_pass_atlogon=dict(type='bool', default=False),
|
||||||
|
auto_updates=dict(type='bool', default=False),
|
||||||
|
enable_winrm=dict(type='bool', default=True),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if not HAS_AZURE:
|
if not HAS_AZURE:
|
||||||
|
|
Loading…
Reference in a new issue