mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adds various provision fixes (#31731)
* vcmp provisioning support * documentation fixes * fixes for python3 causing an exception
This commit is contained in:
parent
53445ded84
commit
0610f09dab
2 changed files with 93 additions and 35 deletions
|
@ -4,14 +4,18 @@
|
||||||
# Copyright (c) 2017 F5 Networks Inc.
|
# Copyright (c) 2017 F5 Networks Inc.
|
||||||
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = r'''
|
||||||
---
|
---
|
||||||
module: bigip_provision
|
module: bigip_provision
|
||||||
short_description: Manage BIG-IP module provisioning.
|
short_description: Manage BIG-IP module provisioning
|
||||||
description:
|
description:
|
||||||
- Manage BIG-IP module provisioning. This module will only provision at the
|
- Manage BIG-IP module provisioning. This module will only provision at the
|
||||||
standard levels of Dedicated, Nominal, and Minimum.
|
standard levels of Dedicated, Nominal, and Minimum.
|
||||||
|
@ -35,6 +39,7 @@ options:
|
||||||
- pem
|
- pem
|
||||||
- sam
|
- sam
|
||||||
- swg
|
- swg
|
||||||
|
- vcmp
|
||||||
level:
|
level:
|
||||||
description:
|
description:
|
||||||
- Sets the provisioning level for the requested modules. Changing the
|
- Sets the provisioning level for the requested modules. Changing the
|
||||||
|
@ -68,45 +73,48 @@ author:
|
||||||
- Tim Rupp (@caphrim007)
|
- Tim Rupp (@caphrim007)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = '''
|
EXAMPLES = r'''
|
||||||
- name: Provision PEM at "nominal" level
|
- name: Provision PEM at "nominal" level
|
||||||
bigip_provision:
|
bigip_provision:
|
||||||
server: "lb.mydomain.com"
|
server: lb.mydomain.com
|
||||||
module: "pem"
|
module: pem
|
||||||
level: "nominal"
|
level: nominal
|
||||||
password: "secret"
|
password: secret
|
||||||
user: "admin"
|
user: admin
|
||||||
validate_certs: "no"
|
validate_certs: no
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Provision a dedicated SWG. This will unprovision every other module
|
- name: Provision a dedicated SWG. This will unprovision every other module
|
||||||
bigip_provision:
|
bigip_provision:
|
||||||
server: "lb.mydomain.com"
|
server: lb.mydomain.com
|
||||||
module: "swg"
|
module: swg
|
||||||
password: "secret"
|
password: secret
|
||||||
level: "dedicated"
|
level: dedicated
|
||||||
user: "admin"
|
user: admin
|
||||||
validate_certs: "no"
|
validate_certs: no
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = r'''
|
||||||
level:
|
level:
|
||||||
description: The new provisioning level of the module.
|
description: The new provisioning level of the module.
|
||||||
returned: changed
|
returned: changed
|
||||||
type: string
|
type: string
|
||||||
sample: "minimum"
|
sample: minimum
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from ansible.module_utils.f5_utils import (
|
from ansible.module_utils.f5_utils import AnsibleF5Client
|
||||||
AnsibleF5Client,
|
from ansible.module_utils.f5_utils import AnsibleF5Parameters
|
||||||
AnsibleF5Parameters,
|
from ansible.module_utils.f5_utils import HAS_F5SDK
|
||||||
HAS_F5SDK,
|
from ansible.module_utils.f5_utils import F5ModuleError
|
||||||
F5ModuleError,
|
from f5.sdk_exception import LazyAttributesRequired
|
||||||
iControlUnexpectedHTTPError
|
|
||||||
)
|
try:
|
||||||
|
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||||
|
except ImportError:
|
||||||
|
HAS_F5SDK = False
|
||||||
|
|
||||||
|
|
||||||
class Parameters(AnsibleF5Parameters):
|
class Parameters(AnsibleF5Parameters):
|
||||||
|
@ -200,7 +208,10 @@ class ModuleManager(object):
|
||||||
if self.client.check_mode:
|
if self.client.check_mode:
|
||||||
return True
|
return True
|
||||||
self.update_on_device()
|
self.update_on_device()
|
||||||
self.wait_for_module_provisioning()
|
self._wait_for_module_provisioning()
|
||||||
|
if self.want.module == 'vcmp':
|
||||||
|
self._wait_for_reboot()
|
||||||
|
self._wait_for_module_provisioning()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def should_update(self):
|
def should_update(self):
|
||||||
|
@ -232,7 +243,15 @@ class ModuleManager(object):
|
||||||
if self.client.check_mode:
|
if self.client.check_mode:
|
||||||
return True
|
return True
|
||||||
self.remove_from_device()
|
self.remove_from_device()
|
||||||
self.wait_for_module_provisioning()
|
self._wait_for_module_provisioning()
|
||||||
|
|
||||||
|
# For vCMP, because it has to reboot, we also wait for mcpd to become available
|
||||||
|
# before "moving on", or else the REST API would not be available and subsequent
|
||||||
|
# Tasks would fail.
|
||||||
|
if self.want.module == 'vcmp':
|
||||||
|
self._wait_for_reboot()
|
||||||
|
self._wait_for_module_provisioning()
|
||||||
|
|
||||||
if self.exists():
|
if self.exists():
|
||||||
raise F5ModuleError("Failed to de-provision the module")
|
raise F5ModuleError("Failed to de-provision the module")
|
||||||
return True
|
return True
|
||||||
|
@ -243,7 +262,7 @@ class ModuleManager(object):
|
||||||
resource = resource.load()
|
resource = resource.load()
|
||||||
resource.update(level='none')
|
resource.update(level='none')
|
||||||
|
|
||||||
def wait_for_module_provisioning(self):
|
def _wait_for_module_provisioning(self):
|
||||||
# To prevent things from running forever, the hack is to check
|
# To prevent things from running forever, the hack is to check
|
||||||
# for mprov's status twice. If mprov is finished, then in most
|
# for mprov's status twice. If mprov is finished, then in most
|
||||||
# cases (not ASM) the provisioning is probably ready.
|
# cases (not ASM) the provisioning is probably ready.
|
||||||
|
@ -252,7 +271,7 @@ class ModuleManager(object):
|
||||||
# Sleep a little to let provisioning settle and begin properly
|
# Sleep a little to let provisioning settle and begin properly
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
while nops < 4:
|
while nops < 3:
|
||||||
try:
|
try:
|
||||||
if not self._is_mprov_running_on_device():
|
if not self._is_mprov_running_on_device():
|
||||||
nops += 1
|
nops += 1
|
||||||
|
@ -261,17 +280,54 @@ class ModuleManager(object):
|
||||||
except Exception:
|
except Exception:
|
||||||
# This can be caused by restjavad restarting.
|
# This can be caused by restjavad restarting.
|
||||||
pass
|
pass
|
||||||
time.sleep(10)
|
time.sleep(5)
|
||||||
|
|
||||||
def _is_mprov_running_on_device(self):
|
def _is_mprov_running_on_device(self):
|
||||||
output = self.client.api.tm.util.bash.exec_cmd(
|
output = self.client.api.tm.util.bash.exec_cmd(
|
||||||
'run',
|
'run',
|
||||||
utilCmdArgs='-c "ps aux | grep \'[m]prov\'"'
|
utilCmdArgs='-c "ps aux | grep \'[m]prov\'"'
|
||||||
)
|
)
|
||||||
if hasattr(output, 'commandResult'):
|
try:
|
||||||
return True
|
if hasattr(output, 'commandResult'):
|
||||||
|
return True
|
||||||
|
except LazyAttributesRequired:
|
||||||
|
pass
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _get_last_reboot(self):
|
||||||
|
output = self.client.api.tm.util.bash.exec_cmd(
|
||||||
|
'run',
|
||||||
|
utilCmdArgs='-c "/usr/bin/last reboot | head - 1"'
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
if hasattr(output, 'commandResult'):
|
||||||
|
return str(output.commandResult)
|
||||||
|
except LazyAttributesRequired:
|
||||||
|
pass
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _wait_for_reboot(self):
|
||||||
|
nops = 0
|
||||||
|
|
||||||
|
last_reboot = self._get_last_reboot()
|
||||||
|
|
||||||
|
# Sleep a little to let provisioning settle and begin properly
|
||||||
|
time.sleep(5)
|
||||||
|
|
||||||
|
while nops < 6:
|
||||||
|
try:
|
||||||
|
next_reboot = self._get_last_reboot()
|
||||||
|
if next_reboot is None:
|
||||||
|
nops = 0
|
||||||
|
if next_reboot == last_reboot:
|
||||||
|
nops = 0
|
||||||
|
else:
|
||||||
|
nops += 1
|
||||||
|
except Exception:
|
||||||
|
# This can be caused by restjavad restarting.
|
||||||
|
pass
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
|
||||||
class ArgumentSpec(object):
|
class ArgumentSpec(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -282,7 +338,7 @@ class ArgumentSpec(object):
|
||||||
choices=[
|
choices=[
|
||||||
'afm', 'am', 'sam', 'asm', 'avr', 'fps',
|
'afm', 'am', 'sam', 'asm', 'avr', 'fps',
|
||||||
'gtm', 'lc', 'ltm', 'pem', 'swg', 'ilx',
|
'gtm', 'lc', 'ltm', 'pem', 'swg', 'ilx',
|
||||||
'apm'
|
'apm', 'vcmp'
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
level=dict(
|
level=dict(
|
||||||
|
|
|
@ -38,11 +38,13 @@ try:
|
||||||
from library.bigip_provision import Parameters
|
from library.bigip_provision import Parameters
|
||||||
from library.bigip_provision import ModuleManager
|
from library.bigip_provision import ModuleManager
|
||||||
from library.bigip_provision import ArgumentSpec
|
from library.bigip_provision import ArgumentSpec
|
||||||
|
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
try:
|
try:
|
||||||
from ansible.modules.network.f5.bigip_provision import Parameters
|
from ansible.modules.network.f5.bigip_provision import Parameters
|
||||||
from ansible.modules.network.f5.bigip_provision import ModuleManager
|
from ansible.modules.network.f5.bigip_provision import ModuleManager
|
||||||
from ansible.modules.network.f5.bigip_provision import ArgumentSpec
|
from ansible.modules.network.f5.bigip_provision import ArgumentSpec
|
||||||
|
from ansible.module_utils.f5_utils import iControlUnexpectedHTTPError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
raise SkipTest("F5 Ansible modules require the f5-sdk Python library")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue