| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
from __future__ import absolute_import, division, print_function |
| 7 |
__metaclass__ = type |
| 8 |
|
| 9 |
DOCUMENTATION = ''' |
| 10 |
--- |
| 11 |
module: nios_adminuser |
| 12 |
author: "Nitish K S (@nitish-ks)" |
| 13 |
short_description: Configure Infoblox NIOS Adminuser |
| 14 |
version_added: "1.8.0" |
| 15 |
description: |
| 16 |
- Adds and/or removes instances of adminuser objects from |
| 17 |
Infoblox NIOS servers. This module manages NIOS C(adminuser) objects |
| 18 |
using the Infoblox WAPI interface over REST. |
| 19 |
requirements: |
| 20 |
- infoblox-client |
| 21 |
extends_documentation_fragment: infoblox.nios_modules.nios |
| 22 |
notes: |
| 23 |
- This module supports C(check_mode). |
| 24 |
options: |
| 25 |
name: |
| 26 |
description: |
| 27 |
- Specifies the adminuser name to add or remove from the system. |
| 28 |
Users can also update the name as it is possible |
| 29 |
to pass a dict containing I(new_name), I(old_name). See examples. |
| 30 |
required: true |
| 31 |
type: str |
| 32 |
admin_groups: |
| 33 |
description: |
| 34 |
- The names of the Admin Groups to which this Admin User belongs. |
| 35 |
Currently, this is limited to only one Admin Group. |
| 36 |
required: true |
| 37 |
type: list |
| 38 |
elements: str |
| 39 |
password: |
| 40 |
description: |
| 41 |
- The password for the administrator to use when logging in. |
| 42 |
type: str |
| 43 |
auth_method: |
| 44 |
description: |
| 45 |
- Authentication method for the admin user. |
| 46 |
default: KEYPAIR |
| 47 |
choices: |
| 48 |
- KEYPAIR |
| 49 |
- KEYPAIR_PASSWORD |
| 50 |
type: str |
| 51 |
auth_type: |
| 52 |
description: |
| 53 |
- Authentication type for the admin user. |
| 54 |
default: LOCAL |
| 55 |
choices: |
| 56 |
- LOCAL |
| 57 |
- REMOTE |
| 58 |
- SAML |
| 59 |
- SAML_LOCAL |
| 60 |
type: str |
| 61 |
ca_certificate_issuer: |
| 62 |
description: |
| 63 |
- The CA certificate that is used for user lookup during authentication. |
| 64 |
type: str |
| 65 |
client_certificate_serial_number: |
| 66 |
description: |
| 67 |
- The serial number of the client certificate. |
| 68 |
type: str |
| 69 |
disable: |
| 70 |
description: |
| 71 |
- Determines whether the admin user is disabled or not. When this is set |
| 72 |
to False, the admin user is enabled. |
| 73 |
default: false |
| 74 |
type: bool |
| 75 |
email: |
| 76 |
description: |
| 77 |
- Email address of the admin user. |
| 78 |
type: str |
| 79 |
enable_certificate_authentication: |
| 80 |
description: |
| 81 |
- Determines whether the user is allowed to log in only with the |
| 82 |
certificate. Regular username/password authentication will be disabled |
| 83 |
for this user. |
| 84 |
default: false |
| 85 |
type: bool |
| 86 |
time_zone: |
| 87 |
description: |
| 88 |
- The time zone for this admin user. |
| 89 |
default: UTC |
| 90 |
type: str |
| 91 |
use_time_zone: |
| 92 |
description: |
| 93 |
- Use flag for I(time_zone). |
| 94 |
default: false |
| 95 |
type: bool |
| 96 |
ssh_keys: |
| 97 |
description: |
| 98 |
- List of SSH keys for the admin user. |
| 99 |
type: list |
| 100 |
default: [] |
| 101 |
elements: dict |
| 102 |
suboptions: |
| 103 |
key_name: |
| 104 |
description: |
| 105 |
- Unique identifier for the key |
| 106 |
type: str |
| 107 |
key_type: |
| 108 |
description: |
| 109 |
- Type of the SSH key. |
| 110 |
choices: |
| 111 |
- ECDSA |
| 112 |
- ED25519 |
| 113 |
- RSA |
| 114 |
type: str |
| 115 |
key_value: |
| 116 |
description: |
| 117 |
- SSH key text. |
| 118 |
type: str |
| 119 |
use_ssh_keys: |
| 120 |
description: |
| 121 |
- Enable/disable the ssh keypair authentication. |
| 122 |
default: false |
| 123 |
type: bool |
| 124 |
extattrs: |
| 125 |
description: |
| 126 |
- Allows for the configuration of Extensible Attributes on the |
| 127 |
instance of the object. This argument accepts a set of key / value |
| 128 |
pairs for configuration. |
| 129 |
type: dict |
| 130 |
comment: |
| 131 |
description: |
| 132 |
- Configures a text string comment to be associated with the instance |
| 133 |
of this object. The provided text string will be configured on the |
| 134 |
object instance. |
| 135 |
type: str |
| 136 |
state: |
| 137 |
description: |
| 138 |
- Configures the intended state of the instance of the object on |
| 139 |
the NIOS server. When this value is set to C(present), the object |
| 140 |
is configured on the device and when this value is set to C(absent) |
| 141 |
the value is removed (if necessary) from the device. |
| 142 |
default: present |
| 143 |
choices: |
| 144 |
- present |
| 145 |
- absent |
| 146 |
type: str |
| 147 |
''' |
| 148 |
|
| 149 |
EXAMPLES = ''' |
| 150 |
- name: Create a new admin user |
| 151 |
infoblox.nios_modules.nios_adminuser: |
| 152 |
name: ansible_user |
| 153 |
admin_groups: admin-group |
| 154 |
password: "secure_password" |
| 155 |
state: present |
| 156 |
provider: |
| 157 |
host: "{{ inventory_hostname_short }}" |
| 158 |
username: admin |
| 159 |
password: admin |
| 160 |
connection: local |
| 161 |
|
| 162 |
- name: Update admin user name |
| 163 |
infoblox.nios_modules.nios_adminuser: |
| 164 |
name: {new_name: new_user, old_name: ansible_user} |
| 165 |
admin_groups: admin-group |
| 166 |
state: present |
| 167 |
provider: |
| 168 |
host: "{{ inventory_hostname_short }}" |
| 169 |
username: admin |
| 170 |
password: admin |
| 171 |
connection: local |
| 172 |
|
| 173 |
- name: Create admin user with remote authentication |
| 174 |
infoblox.nios_modules.nios_adminuser: |
| 175 |
name: remote_admin_user |
| 176 |
admin_groups: admin-group |
| 177 |
auth_type: "REMOTE" |
| 178 |
email: "[email protected]" |
| 179 |
use_time_zone: true |
| 180 |
time_zone: 'US/Hawaii' |
| 181 |
extattrs: |
| 182 |
Site: "USA" |
| 183 |
state: present |
| 184 |
provider: |
| 185 |
host: "{{ inventory_hostname_short }}" |
| 186 |
username: admin |
| 187 |
password: admin |
| 188 |
connection: local |
| 189 |
|
| 190 |
- name: Create admin user with ssh keys |
| 191 |
infoblox.nios_modules.nios_adminuser: |
| 192 |
name: cloud_user |
| 193 |
admin_groups: cloud-api-only |
| 194 |
comment: "Created by Ansible" |
| 195 |
disable : false |
| 196 |
password: "secure_password" |
| 197 |
use_ssh_keys: true |
| 198 |
ssh_keys: |
| 199 |
- key_name: "sshkey1" |
| 200 |
key_type: "RSA" |
| 201 |
key_value: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}" |
| 202 |
- key_name: "sshkey2" |
| 203 |
key_type: "ECDSA" |
| 204 |
key_value: "{{ lookup('file', '~/.ssh/id_ecdsa.pub') }}" |
| 205 |
state: present |
| 206 |
provider: |
| 207 |
host: "{{ inventory_hostname_short }}" |
| 208 |
username: admin |
| 209 |
password: admin |
| 210 |
connection: local |
| 211 |
|
| 212 |
- name: Update admin user to enable certificate authentication |
| 213 |
infoblox.nios_modules.nios_adminuser: |
| 214 |
name: admin_user |
| 215 |
admin_groups: admin-group |
| 216 |
enable_certificate_authentication: true |
| 217 |
ca_certificate_issuer: 'CN="ib-root-ca"' |
| 218 |
client_certificate_serial_number: "397F9435000100000031" |
| 219 |
state: present |
| 220 |
provider: |
| 221 |
host: "{{ inventory_hostname_short }}" |
| 222 |
username: admin |
| 223 |
password: admin |
| 224 |
connection: local |
| 225 |
|
| 226 |
- name: Remove admin user |
| 227 |
infoblox.nios_modules.nios_adminuser: |
| 228 |
name: new_user |
| 229 |
admin_groups: admin-group |
| 230 |
state: absent |
| 231 |
provider: |
| 232 |
host: "{{ inventory_hostname_short }}" |
| 233 |
username: admin |
| 234 |
password: admin |
| 235 |
connection: local |
| 236 |
''' |
| 237 |
|
| 238 |
RETURN = ''' # ''' |
| 239 |
|
| 240 |
from ansible.module_utils.basic import AnsibleModule |
| 241 |
from ..module_utils.api import WapiModule |
| 242 |
from ..module_utils.api import NIOS_ADMINUSER |
| 243 |
from ..module_utils.api import normalize_ib_spec |
| 244 |
|
| 245 |
|
| 246 |
def main(): |
| 247 |
''' Main entry point for module execution |
| 248 |
''' |
| 249 |
|
| 250 |
def cacert_transform(module): |
| 251 |
cacert_ref = str() |
| 252 |
|
| 253 |
if not all([module.params.get('ca_certificate_issuer'), module.params.get('client_certificate_serial_number')]): |
| 254 |
return None |
| 255 |
|
| 256 |
if not module.params['client_certificate_serial_number']: |
| 257 |
module.fail_json( |
| 258 |
msg='Client certificate Serial Number is required.') |
| 259 |
|
| 260 |
cacert = wapi.get_object( |
| 261 |
'cacertificate', |
| 262 |
{ |
| 263 |
'issuer': module.params['ca_certificate_issuer'], |
| 264 |
'serial': module.params['client_certificate_serial_number'] |
| 265 |
}) |
| 266 |
if cacert: |
| 267 |
cacert_ref = cacert[0]['_ref'] |
| 268 |
else: |
| 269 |
module.fail_json( |
| 270 |
msg='CA Certificate \'%s\' could not be found. ' |
| 271 |
'Provide a valid certificate Issuer and Serial Number.' % |
| 272 |
module.params['ca_certificate_issuer']) |
| 273 |
return cacert_ref |
| 274 |
|
| 275 |
ssh_key_spec = dict( |
| 276 |
key_name=dict(type='str'), |
| 277 |
key_type=dict(type='str', choices=['ECDSA', 'ED25519', 'RSA']), |
| 278 |
key_value=dict(type='str', no_log=True) |
| 279 |
) |
| 280 |
|
| 281 |
ib_spec = dict( |
| 282 |
name=dict(required=True, ib_req=True), |
| 283 |
admin_groups=dict(type='list', elements='str', required=True, ib_req=True), |
| 284 |
password=dict(no_log=True), |
| 285 |
auth_method=dict(default='KEYPAIR', choices=['KEYPAIR', 'KEYPAIR_PASSWORD']), |
| 286 |
auth_type=dict(default='LOCAL', choices=['LOCAL', 'REMOTE', 'SAML', 'SAML_LOCAL']), |
| 287 |
ca_certificate_issuer=dict(transform=cacert_transform), |
| 288 |
client_certificate_serial_number=dict(), |
| 289 |
disable=dict(type='bool', default=False), |
| 290 |
email=dict(), |
| 291 |
enable_certificate_authentication=dict(type='bool', default=False), |
| 292 |
time_zone=dict(default='UTC'), |
| 293 |
use_time_zone=dict(type='bool', default=False), |
| 294 |
ssh_keys=dict(type='list', default=[], no_log=False, elements='dict', options=ssh_key_spec), |
| 295 |
use_ssh_keys=dict(type='bool', default=False), |
| 296 |
extattrs=dict(type='dict'), |
| 297 |
comment=dict() |
| 298 |
) |
| 299 |
|
| 300 |
argument_spec = dict( |
| 301 |
provider=dict(required=True), |
| 302 |
state=dict(default='present', choices=['present', 'absent']) |
| 303 |
) |
| 304 |
|
| 305 |
argument_spec.update(normalize_ib_spec(ib_spec)) |
| 306 |
argument_spec.update(WapiModule.provider_spec) |
| 307 |
|
| 308 |
module = AnsibleModule(argument_spec=argument_spec, |
| 309 |
supports_check_mode=True) |
| 310 |
|
| 311 |
wapi = WapiModule(module) |
| 312 |
result = wapi.run(NIOS_ADMINUSER, ib_spec) |
| 313 |
|
| 314 |
module.exit_json(**result) |
| 315 |
|
| 316 |
|
| 317 |
if __name__ == '__main__': |
| 318 |
main() |