mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Reduced states to present and absent. Power states are now bool options.
This commit is contained in:
parent
a67e9f3122
commit
ae30540ca2
1 changed files with 31 additions and 29 deletions
|
@ -47,28 +47,32 @@ options:
|
||||||
description:
|
description:
|
||||||
- Assert the state of the virtual machine.
|
- Assert the state of the virtual machine.
|
||||||
- State 'present' will check that the machine exists with the requested configuration. If the configuration
|
- State 'present' will check that the machine exists with the requested configuration. If the configuration
|
||||||
of the existing machine does not match, the machine will be updated. If the machine is updated, it will
|
of the existing machine does not match, the machine will be updated. Use options start, stop,
|
||||||
be left in a powered on or running state. Otherwise, the final state of the machine will remain untouched.
|
deallocate and restart to change the machine's power state.
|
||||||
- State 'started' will also check that the machine exists with the requested configuration, updating it, if
|
- State 'absent' will remove the virtual machine.
|
||||||
needed and leaving the machine in a powered on state.
|
default: present
|
||||||
- State 'stopped' will also check that the machine exists with the requested configuration, updating it, if
|
|
||||||
needed and leaving the machine in a powered off state. Pass deallocate to put the machine in a
|
|
||||||
'deallocated' state.
|
|
||||||
default: started
|
|
||||||
required: false
|
required: false
|
||||||
choices:
|
choices:
|
||||||
- absent
|
- absent
|
||||||
- present
|
- present
|
||||||
- started
|
start:
|
||||||
- stopped
|
description:
|
||||||
|
- Use with state 'present' to start the machine.
|
||||||
|
default: true
|
||||||
|
required: false
|
||||||
|
stop:
|
||||||
|
description:
|
||||||
|
- Use with state 'present' to stop the machine.
|
||||||
|
default: false
|
||||||
|
required: false
|
||||||
deallocate:
|
deallocate:
|
||||||
description:
|
description:
|
||||||
- Use with state 'stopped' to put the VM in a deallocated state.
|
- Use with state 'present' to put the VM in a deallocated state.
|
||||||
default: false
|
default: false
|
||||||
required: false
|
required: false
|
||||||
restart:
|
restart:
|
||||||
description:
|
description:
|
||||||
- Use with state 'present' or 'started' to restart a running VM.
|
- Use with state 'present' to restart a running VM.
|
||||||
default: false
|
default: false
|
||||||
required: false
|
required: false
|
||||||
location:
|
location:
|
||||||
|
@ -279,13 +283,12 @@ EXAMPLES = '''
|
||||||
azure_rm_virtualmachine:
|
azure_rm_virtualmachine:
|
||||||
resource_group: Testing
|
resource_group: Testing
|
||||||
name: testvm002
|
name: testvm002
|
||||||
state: stopped
|
stop: yes
|
||||||
|
|
||||||
- name: Deallocate
|
- name: Deallocate
|
||||||
azure_rm_virtualmachine:
|
azure_rm_virtualmachine:
|
||||||
resource_group: Testing
|
resource_group: Testing
|
||||||
name: testvm002
|
name: testvm002
|
||||||
state: stopped
|
|
||||||
deallocate: yes
|
deallocate: yes
|
||||||
|
|
||||||
- name: Power On
|
- name: Power On
|
||||||
|
@ -302,11 +305,6 @@ EXAMPLES = '''
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
changed:
|
|
||||||
description: Whether or not the object was changed.
|
|
||||||
returned: always
|
|
||||||
type: bool
|
|
||||||
sample: True
|
|
||||||
actions:
|
actions:
|
||||||
description: List of descriptive actions performed by the module.
|
description: List of descriptive actions performed by the module.
|
||||||
returned: always
|
returned: always
|
||||||
|
@ -315,7 +313,7 @@ actions:
|
||||||
"Powered on virtual machine testvm10"
|
"Powered on virtual machine testvm10"
|
||||||
]
|
]
|
||||||
differences:
|
differences:
|
||||||
description: List of differences between the requested configuraiton and actual VM configuration.
|
description: List of differences between the requested configuration and actual VM configuration.
|
||||||
returned: always
|
returned: always
|
||||||
type: list
|
type: list
|
||||||
sample: []
|
sample: []
|
||||||
|
@ -495,7 +493,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
self.module_arg_spec = dict(
|
self.module_arg_spec = dict(
|
||||||
resource_group=dict(type='str', required=True),
|
resource_group=dict(type='str', required=True),
|
||||||
name=dict(type='str', required=True),
|
name=dict(type='str', required=True),
|
||||||
state=dict(choices=['present', 'absent', 'started', 'stopped'], default='started', type='str'),
|
state=dict(choices=['present', 'absent'], default='present', type='str'),
|
||||||
location=dict(type='str'),
|
location=dict(type='str'),
|
||||||
short_hostname=dict(type='str'),
|
short_hostname=dict(type='str'),
|
||||||
vm_size=dict(type='str', choices=[], default='Standard_D1'),
|
vm_size=dict(type='str', choices=[], default='Standard_D1'),
|
||||||
|
@ -520,7 +518,9 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
virtual_network_name=dict(type='str', aliases=['virtual_network']),
|
virtual_network_name=dict(type='str', aliases=['virtual_network']),
|
||||||
subnet_name=dict(type='str', aliases=['subnet']),
|
subnet_name=dict(type='str', aliases=['subnet']),
|
||||||
deallocate=dict(type='bool', default=False),
|
deallocate=dict(type='bool', default=False),
|
||||||
restart=dict(type='bool', default=False)
|
restart=dict(type='bool', default=False),
|
||||||
|
start=dict(type='bool', default=True),
|
||||||
|
stop=dict(type='bool', default=False),
|
||||||
)
|
)
|
||||||
|
|
||||||
for key in VirtualMachineSizeTypes:
|
for key in VirtualMachineSizeTypes:
|
||||||
|
@ -554,6 +554,8 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
self.subnet_name = None
|
self.subnet_name = None
|
||||||
self.deallocate = None
|
self.deallocate = None
|
||||||
self.restart = None
|
self.restart = None
|
||||||
|
self.start = None
|
||||||
|
self.stop = None
|
||||||
|
|
||||||
self.results = dict(
|
self.results = dict(
|
||||||
changed=False,
|
changed=False,
|
||||||
|
@ -585,7 +587,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
# Set default location
|
# Set default location
|
||||||
self.location = resource_group.location
|
self.location = resource_group.location
|
||||||
|
|
||||||
if self.state in ('present', 'started', 'stopped'):
|
if self.state == 'present':
|
||||||
# Verify parameters and resolve any defaults
|
# Verify parameters and resolve any defaults
|
||||||
|
|
||||||
if self.vm_size and not self.vm_size_is_valid():
|
if self.vm_size and not self.vm_size_is_valid():
|
||||||
|
@ -634,7 +636,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
self.check_provisioning_state(vm, self.state)
|
self.check_provisioning_state(vm, self.state)
|
||||||
vm_dict = self.serialize_vm(vm)
|
vm_dict = self.serialize_vm(vm)
|
||||||
|
|
||||||
if self.state in ('present', 'started', 'stopped'):
|
if self.state == 'present':
|
||||||
differences = []
|
differences = []
|
||||||
current_nics = []
|
current_nics = []
|
||||||
results = vm_dict
|
results = vm_dict
|
||||||
|
@ -671,21 +673,21 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
|
|
||||||
self.results['differences'] = differences
|
self.results['differences'] = differences
|
||||||
|
|
||||||
if self.state == 'started' and vm_dict['powerstate'] != 'running':
|
if self.start and vm_dict['powerstate'] != 'running':
|
||||||
self.log("CHANGED: virtual machine {0} not running and requested state 'running'".format(self.name))
|
self.log("CHANGED: virtual machine {0} not running and requested state 'running'".format(self.name))
|
||||||
changed = True
|
changed = True
|
||||||
powerstate_change = 'poweron'
|
powerstate_change = 'poweron'
|
||||||
elif self.state in ('started', 'present') and vm_dict['powerstate'] == 'running' and self.restart:
|
elif self.state == 'present' and vm_dict['powerstate'] == 'running' and self.restart:
|
||||||
self.log("CHANGED: virtual machine {0} {1} and requested state 'restarted'"
|
self.log("CHANGED: virtual machine {0} {1} and requested state 'restarted'"
|
||||||
.format(self.name, vm_dict['powerstate']))
|
.format(self.name, vm_dict['powerstate']))
|
||||||
changed = True
|
changed = True
|
||||||
powerstate_change = 'restarted'
|
powerstate_change = 'restarted'
|
||||||
elif self.state == 'stopped' and self.deallocate and vm_dict['powerstate'] != 'deallocated':
|
elif self.state == 'present' and self.deallocate and vm_dict['powerstate'] != 'deallocated':
|
||||||
self.log("CHANGED: virtual machine {0} {1} and requested state 'deallocated'"
|
self.log("CHANGED: virtual machine {0} {1} and requested state 'deallocated'"
|
||||||
.format(self.name, vm_dict['powerstate']))
|
.format(self.name, vm_dict['powerstate']))
|
||||||
changed = True
|
changed = True
|
||||||
powerstate_change = 'deallocated'
|
powerstate_change = 'deallocated'
|
||||||
elif self.state == 'stopped' and vm_dict['powerstate'] == 'running':
|
elif self.stop and vm_dict['powerstate'] == 'running':
|
||||||
self.log("CHANGED: virtual machine {0} running and requested state 'stopped'".format(self.name))
|
self.log("CHANGED: virtual machine {0} running and requested state 'stopped'".format(self.name))
|
||||||
changed = True
|
changed = True
|
||||||
powerstate_change = 'poweroff'
|
powerstate_change = 'poweroff'
|
||||||
|
@ -710,7 +712,7 @@ class AzureRMVirtualMachine(AzureRMModuleBase):
|
||||||
return self.results
|
return self.results
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
if self.state in ('present', 'started', 'stopped'):
|
if self.state == 'present':
|
||||||
if not vm:
|
if not vm:
|
||||||
# Create the VM
|
# Create the VM
|
||||||
self.log("Create virtual machine {0}".format(self.name))
|
self.log("Create virtual machine {0}".format(self.name))
|
||||||
|
|
Loading…
Reference in a new issue