1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

rewritten as list literals (#2160)

* rewritten as list literals

* added changelog fragment
This commit is contained in:
Alexei Znamensky 2021-04-05 19:22:06 +12:00 committed by GitHub
parent d92d0632eb
commit b97e31dd55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 55 additions and 94 deletions

View file

@ -0,0 +1,11 @@
minor_changes:
- hiera lookup - minor refactor converting multiple statements to a single list literal (https://github.com/ansible-collections/community.general/pull/2160).
- known_hosts module utils - minor refactor converting multiple statements to a single list literal (https://github.com/ansible-collections/community.general/pull/2160).
- nictagadm - minor refactor converting multiple statements to a single list literal (https://github.com/ansible-collections/community.general/pull/2160).
- smartos_image_info - minor refactor converting multiple statements to a single list literal (https://github.com/ansible-collections/community.general/pull/2160).
- xattr - minor refactor converting multiple statements to a single list literal (https://github.com/ansible-collections/community.general/pull/2160).
- ipwcli_dns - minor refactor converting multiple statements to a single list literal (https://github.com/ansible-collections/community.general/pull/2160).
- svr4pkg - minor refactor converting multiple statements to a single list literal (https://github.com/ansible-collections/community.general/pull/2160).
- zfs_facts - minor refactor converting multiple statements to a single list literal (https://github.com/ansible-collections/community.general/pull/2160).
- zpool_facts - minor refactor converting multiple statements to a single list literal (https://github.com/ansible-collections/community.general/pull/2160).
- beadm - minor refactor converting multiple statements to a single list literal (https://github.com/ansible-collections/community.general/pull/2160).

View file

@ -84,7 +84,5 @@ class Hiera(object):
class LookupModule(LookupBase): class LookupModule(LookupBase):
def run(self, terms, variables=''): def run(self, terms, variables=''):
hiera = Hiera() hiera = Hiera()
ret = [] ret = [hiera.get(terms)]
ret.append(hiera.get(terms))
return ret return ret

View file

@ -87,11 +87,12 @@ def not_in_host_file(self, host):
user_host_file = "~/.ssh/known_hosts" user_host_file = "~/.ssh/known_hosts"
user_host_file = os.path.expanduser(user_host_file) user_host_file = os.path.expanduser(user_host_file)
host_file_list = [] host_file_list = [
host_file_list.append(user_host_file) user_host_file,
host_file_list.append("/etc/ssh/ssh_known_hosts") "/etc/ssh/ssh_known_hosts",
host_file_list.append("/etc/ssh/ssh_known_hosts2") "/etc/ssh/ssh_known_hosts2",
host_file_list.append("/etc/openssh/ssh_known_hosts") "/etc/openssh/ssh_known_hosts",
]
hfiles_not_found = 0 hfiles_not_found = 0
for hf in host_file_list: for hf in host_file_list:

View file

@ -119,20 +119,13 @@ class NicTag(object):
return is_mac(self.mac.lower()) return is_mac(self.mac.lower())
def nictag_exists(self): def nictag_exists(self):
cmd = [self.nictagadm_bin] cmd = [self.nictagadm_bin, 'exists', self.name]
cmd.append('exists')
cmd.append(self.name)
(rc, dummy, dummy) = self.module.run_command(cmd) (rc, dummy, dummy) = self.module.run_command(cmd)
return rc == 0 return rc == 0
def add_nictag(self): def add_nictag(self):
cmd = [self.nictagadm_bin] cmd = [self.nictagadm_bin, '-v', 'add']
cmd.append('-v')
cmd.append('add')
if self.etherstub: if self.etherstub:
cmd.append('-l') cmd.append('-l')
@ -150,10 +143,7 @@ class NicTag(object):
return self.module.run_command(cmd) return self.module.run_command(cmd)
def delete_nictag(self): def delete_nictag(self):
cmd = [self.nictagadm_bin] cmd = [self.nictagadm_bin, '-v', 'delete']
cmd.append('-v')
cmd.append('delete')
if self.force: if self.force:
cmd.append('-f') cmd.append('-f')

View file

@ -72,10 +72,7 @@ class ImageFacts(object):
self.filters = module.params['filters'] self.filters = module.params['filters']
def return_all_installed_images(self): def return_all_installed_images(self):
cmd = [self.module.get_bin_path('imgadm')] cmd = [self.module.get_bin_path('imgadm'), 'list', '-j']
cmd.append('list')
cmd.append('-j')
if self.filters: if self.filters:
cmd.append(self.filters) cmd.append(self.filters)

View file

@ -98,9 +98,8 @@ from ansible.module_utils._text import to_native
def get_xattr_keys(module, path, follow): def get_xattr_keys(module, path, follow):
cmd = [module.get_bin_path('getfattr', True)] cmd = [module.get_bin_path('getfattr', True), '--absolute-names']
# prevents warning and not sure why it's not default
cmd.append('--absolute-names')
if not follow: if not follow:
cmd.append('-h') cmd.append('-h')
cmd.append(path) cmd.append(path)
@ -109,10 +108,8 @@ def get_xattr_keys(module, path, follow):
def get_xattr(module, path, key, follow): def get_xattr(module, path, key, follow):
cmd = [module.get_bin_path('getfattr', True), '--absolute-names']
cmd = [module.get_bin_path('getfattr', True)]
# prevents warning and not sure why it's not default
cmd.append('--absolute-names')
if not follow: if not follow:
cmd.append('-h') cmd.append('-h')
if key is None: if key is None:

View file

@ -205,9 +205,11 @@ class ResourceRecord(object):
def list_record(self, record): def list_record(self, record):
# check if the record exists via list on ipwcli # check if the record exists via list on ipwcli
search = 'list %s' % (record.replace(';', '&&').replace('set', 'where')) search = 'list %s' % (record.replace(';', '&&').replace('set', 'where'))
cmd = [self.module.get_bin_path('ipwcli', True)] cmd = [
cmd.append('-user=%s' % (self.user)) self.module.get_bin_path('ipwcli', True),
cmd.append('-password=%s' % (self.password)) '-user=%s' % self.user,
'-password=%s' % self.password,
]
rc, out, err = self.module.run_command(cmd, data=search) rc, out, err = self.module.run_command(cmd, data=search)
if 'Invalid username or password' in out: if 'Invalid username or password' in out:
@ -222,9 +224,11 @@ class ResourceRecord(object):
def deploy_record(self, record): def deploy_record(self, record):
# check what happens if create fails on ipworks # check what happens if create fails on ipworks
stdin = 'create %s' % (record) stdin = 'create %s' % (record)
cmd = [self.module.get_bin_path('ipwcli', True)] cmd = [
cmd.append('-user=%s' % (self.user)) self.module.get_bin_path('ipwcli', True),
cmd.append('-password=%s' % (self.password)) '-user=%s' % self.user,
'-password=%s' % self.password,
]
rc, out, err = self.module.run_command(cmd, data=stdin) rc, out, err = self.module.run_command(cmd, data=stdin)
if 'Invalid username or password' in out: if 'Invalid username or password' in out:
@ -238,9 +242,11 @@ class ResourceRecord(object):
def delete_record(self, record): def delete_record(self, record):
# check what happens if create fails on ipworks # check what happens if create fails on ipworks
stdin = 'delete %s' % (record.replace(';', '&&').replace('set', 'where')) stdin = 'delete %s' % (record.replace(';', '&&').replace('set', 'where'))
cmd = [self.module.get_bin_path('ipwcli', True)] cmd = [
cmd.append('-user=%s' % (self.user)) self.module.get_bin_path('ipwcli', True),
cmd.append('-password=%s' % (self.password)) '-user=%s' % self.user,
'-password=%s' % self.password,
]
rc, out, err = self.module.run_command(cmd, data=stdin) rc, out, err = self.module.run_command(cmd, data=stdin)
if 'Invalid username or password' in out: if 'Invalid username or password' in out:

View file

@ -108,8 +108,7 @@ from ansible.module_utils.basic import AnsibleModule
def package_installed(module, name, category): def package_installed(module, name, category):
cmd = [module.get_bin_path('pkginfo', True)] cmd = [module.get_bin_path('pkginfo', True), '-q']
cmd.append('-q')
if category: if category:
cmd.append('-c') cmd.append('-c')
cmd.append(name) cmd.append(name)

View file

@ -175,10 +175,7 @@ class ZFSFacts(object):
self.facts = [] self.facts = []
def dataset_exists(self): def dataset_exists(self):
cmd = [self.module.get_bin_path('zfs')] cmd = [self.module.get_bin_path('zfs'), 'list', self.name]
cmd.append('list')
cmd.append(self.name)
(rc, out, err) = self.module.run_command(cmd) (rc, out, err) = self.module.run_command(cmd)
@ -188,10 +185,7 @@ class ZFSFacts(object):
return False return False
def get_facts(self): def get_facts(self):
cmd = [self.module.get_bin_path('zfs')] cmd = [self.module.get_bin_path('zfs'), 'get', '-H']
cmd.append('get')
cmd.append('-H')
if self.parsable: if self.parsable:
cmd.append('-p') cmd.append('-p')
if self.recurse: if self.recurse:
@ -202,10 +196,7 @@ class ZFSFacts(object):
if self.type: if self.type:
cmd.append('-t') cmd.append('-t')
cmd.append(self.type) cmd.append(self.type)
cmd.append('-o') cmd.extend(['-o', 'name,property,value', self.properties, self.name])
cmd.append('name,property,value')
cmd.append(self.properties)
cmd.append(self.name)
(rc, out, err) = self.module.run_command(cmd) (rc, out, err) = self.module.run_command(cmd)

View file

@ -134,10 +134,7 @@ class ZPoolFacts(object):
self.facts = [] self.facts = []
def pool_exists(self): def pool_exists(self):
cmd = [self.module.get_bin_path('zpool')] cmd = [self.module.get_bin_path('zpool'), 'list', self.name]
cmd.append('list')
cmd.append(self.name)
(rc, out, err) = self.module.run_command(cmd) (rc, out, err) = self.module.run_command(cmd)
@ -147,10 +144,7 @@ class ZPoolFacts(object):
return False return False
def get_facts(self): def get_facts(self):
cmd = [self.module.get_bin_path('zpool')] cmd = [self.module.get_bin_path('zpool'), 'get', '-H']
cmd.append('get')
cmd.append('-H')
if self.parsable: if self.parsable:
cmd.append('-p') cmd.append('-p')
cmd.append('-o') cmd.append('-o')

View file

@ -154,9 +154,7 @@ class BE(object):
self.is_freebsd = os.uname()[0] == 'FreeBSD' self.is_freebsd = os.uname()[0] == 'FreeBSD'
def _beadm_list(self): def _beadm_list(self):
cmd = [self.module.get_bin_path('beadm')] cmd = [self.module.get_bin_path('beadm'), 'list', '-H']
cmd.append('list')
cmd.append('-H')
if '@' in self.name: if '@' in self.name:
cmd.append('-s') cmd.append('-s')
return self.module.run_command(cmd) return self.module.run_command(cmd)
@ -218,42 +216,26 @@ class BE(object):
return False return False
def activate_be(self): def activate_be(self):
cmd = [self.module.get_bin_path('beadm')] cmd = [self.module.get_bin_path('beadm'), 'activate', self.name]
cmd.append('activate')
cmd.append(self.name)
return self.module.run_command(cmd) return self.module.run_command(cmd)
def create_be(self): def create_be(self):
cmd = [self.module.get_bin_path('beadm')] cmd = [self.module.get_bin_path('beadm'), 'create']
cmd.append('create')
if self.snapshot: if self.snapshot:
cmd.append('-e') cmd.extend(['-e', self.snapshot])
cmd.append(self.snapshot)
if not self.is_freebsd: if not self.is_freebsd:
if self.description: if self.description:
cmd.append('-d') cmd.extend(['-d', self.description])
cmd.append(self.description)
if self.options: if self.options:
cmd.append('-o') cmd.extend(['-o', self.options])
cmd.append(self.options)
cmd.append(self.name) cmd.append(self.name)
return self.module.run_command(cmd) return self.module.run_command(cmd)
def destroy_be(self): def destroy_be(self):
cmd = [self.module.get_bin_path('beadm')] cmd = [self.module.get_bin_path('beadm'), 'destroy', '-F', self.name]
cmd.append('destroy')
cmd.append('-F')
cmd.append(self.name)
return self.module.run_command(cmd) return self.module.run_command(cmd)
def is_mounted(self): def is_mounted(self):
@ -276,10 +258,7 @@ class BE(object):
return False return False
def mount_be(self): def mount_be(self):
cmd = [self.module.get_bin_path('beadm')] cmd = [self.module.get_bin_path('beadm'), 'mount', self.name]
cmd.append('mount')
cmd.append(self.name)
if self.mountpoint: if self.mountpoint:
cmd.append(self.mountpoint) cmd.append(self.mountpoint)
@ -287,9 +266,7 @@ class BE(object):
return self.module.run_command(cmd) return self.module.run_command(cmd)
def unmount_be(self): def unmount_be(self):
cmd = [self.module.get_bin_path('beadm')] cmd = [self.module.get_bin_path('beadm'), 'unmount']
cmd.append('unmount')
if self.force: if self.force:
cmd.append('-f') cmd.append('-f')
cmd.append(self.name) cmd.append(self.name)