mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* rewritten as list literals
* added changelog fragment
(cherry picked from commit b97e31dd55
)
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
parent
055c8dac9c
commit
996ef6ab49
11 changed files with 55 additions and 94 deletions
11
changelogs/fragments/2160-list-literals.yml
Normal file
11
changelogs/fragments/2160-list-literals.yml
Normal 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).
|
|
@ -84,7 +84,5 @@ class Hiera(object):
|
|||
class LookupModule(LookupBase):
|
||||
def run(self, terms, variables=''):
|
||||
hiera = Hiera()
|
||||
ret = []
|
||||
|
||||
ret.append(hiera.get(terms))
|
||||
ret = [hiera.get(terms)]
|
||||
return ret
|
||||
|
|
|
@ -87,11 +87,12 @@ def not_in_host_file(self, host):
|
|||
user_host_file = "~/.ssh/known_hosts"
|
||||
user_host_file = os.path.expanduser(user_host_file)
|
||||
|
||||
host_file_list = []
|
||||
host_file_list.append(user_host_file)
|
||||
host_file_list.append("/etc/ssh/ssh_known_hosts")
|
||||
host_file_list.append("/etc/ssh/ssh_known_hosts2")
|
||||
host_file_list.append("/etc/openssh/ssh_known_hosts")
|
||||
host_file_list = [
|
||||
user_host_file,
|
||||
"/etc/ssh/ssh_known_hosts",
|
||||
"/etc/ssh/ssh_known_hosts2",
|
||||
"/etc/openssh/ssh_known_hosts",
|
||||
]
|
||||
|
||||
hfiles_not_found = 0
|
||||
for hf in host_file_list:
|
||||
|
|
|
@ -119,20 +119,13 @@ class NicTag(object):
|
|||
return is_mac(self.mac.lower())
|
||||
|
||||
def nictag_exists(self):
|
||||
cmd = [self.nictagadm_bin]
|
||||
|
||||
cmd.append('exists')
|
||||
cmd.append(self.name)
|
||||
|
||||
cmd = [self.nictagadm_bin, 'exists', self.name]
|
||||
(rc, dummy, dummy) = self.module.run_command(cmd)
|
||||
|
||||
return rc == 0
|
||||
|
||||
def add_nictag(self):
|
||||
cmd = [self.nictagadm_bin]
|
||||
|
||||
cmd.append('-v')
|
||||
cmd.append('add')
|
||||
cmd = [self.nictagadm_bin, '-v', 'add']
|
||||
|
||||
if self.etherstub:
|
||||
cmd.append('-l')
|
||||
|
@ -150,10 +143,7 @@ class NicTag(object):
|
|||
return self.module.run_command(cmd)
|
||||
|
||||
def delete_nictag(self):
|
||||
cmd = [self.nictagadm_bin]
|
||||
|
||||
cmd.append('-v')
|
||||
cmd.append('delete')
|
||||
cmd = [self.nictagadm_bin, '-v', 'delete']
|
||||
|
||||
if self.force:
|
||||
cmd.append('-f')
|
||||
|
|
|
@ -72,10 +72,7 @@ class ImageFacts(object):
|
|||
self.filters = module.params['filters']
|
||||
|
||||
def return_all_installed_images(self):
|
||||
cmd = [self.module.get_bin_path('imgadm')]
|
||||
|
||||
cmd.append('list')
|
||||
cmd.append('-j')
|
||||
cmd = [self.module.get_bin_path('imgadm'), 'list', '-j']
|
||||
|
||||
if self.filters:
|
||||
cmd.append(self.filters)
|
||||
|
|
|
@ -98,9 +98,8 @@ from ansible.module_utils._text import to_native
|
|||
|
||||
|
||||
def get_xattr_keys(module, path, follow):
|
||||
cmd = [module.get_bin_path('getfattr', True)]
|
||||
# prevents warning and not sure why it's not default
|
||||
cmd.append('--absolute-names')
|
||||
cmd = [module.get_bin_path('getfattr', True), '--absolute-names']
|
||||
|
||||
if not follow:
|
||||
cmd.append('-h')
|
||||
cmd.append(path)
|
||||
|
@ -109,10 +108,8 @@ def get_xattr_keys(module, path, 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:
|
||||
cmd.append('-h')
|
||||
if key is None:
|
||||
|
|
|
@ -205,9 +205,11 @@ class ResourceRecord(object):
|
|||
def list_record(self, record):
|
||||
# check if the record exists via list on ipwcli
|
||||
search = 'list %s' % (record.replace(';', '&&').replace('set', 'where'))
|
||||
cmd = [self.module.get_bin_path('ipwcli', True)]
|
||||
cmd.append('-user=%s' % (self.user))
|
||||
cmd.append('-password=%s' % (self.password))
|
||||
cmd = [
|
||||
self.module.get_bin_path('ipwcli', True),
|
||||
'-user=%s' % self.user,
|
||||
'-password=%s' % self.password,
|
||||
]
|
||||
rc, out, err = self.module.run_command(cmd, data=search)
|
||||
|
||||
if 'Invalid username or password' in out:
|
||||
|
@ -222,9 +224,11 @@ class ResourceRecord(object):
|
|||
def deploy_record(self, record):
|
||||
# check what happens if create fails on ipworks
|
||||
stdin = 'create %s' % (record)
|
||||
cmd = [self.module.get_bin_path('ipwcli', True)]
|
||||
cmd.append('-user=%s' % (self.user))
|
||||
cmd.append('-password=%s' % (self.password))
|
||||
cmd = [
|
||||
self.module.get_bin_path('ipwcli', True),
|
||||
'-user=%s' % self.user,
|
||||
'-password=%s' % self.password,
|
||||
]
|
||||
rc, out, err = self.module.run_command(cmd, data=stdin)
|
||||
|
||||
if 'Invalid username or password' in out:
|
||||
|
@ -238,9 +242,11 @@ class ResourceRecord(object):
|
|||
def delete_record(self, record):
|
||||
# check what happens if create fails on ipworks
|
||||
stdin = 'delete %s' % (record.replace(';', '&&').replace('set', 'where'))
|
||||
cmd = [self.module.get_bin_path('ipwcli', True)]
|
||||
cmd.append('-user=%s' % (self.user))
|
||||
cmd.append('-password=%s' % (self.password))
|
||||
cmd = [
|
||||
self.module.get_bin_path('ipwcli', True),
|
||||
'-user=%s' % self.user,
|
||||
'-password=%s' % self.password,
|
||||
]
|
||||
rc, out, err = self.module.run_command(cmd, data=stdin)
|
||||
|
||||
if 'Invalid username or password' in out:
|
||||
|
|
|
@ -108,8 +108,7 @@ from ansible.module_utils.basic import AnsibleModule
|
|||
|
||||
|
||||
def package_installed(module, name, category):
|
||||
cmd = [module.get_bin_path('pkginfo', True)]
|
||||
cmd.append('-q')
|
||||
cmd = [module.get_bin_path('pkginfo', True), '-q']
|
||||
if category:
|
||||
cmd.append('-c')
|
||||
cmd.append(name)
|
||||
|
|
|
@ -175,10 +175,7 @@ class ZFSFacts(object):
|
|||
self.facts = []
|
||||
|
||||
def dataset_exists(self):
|
||||
cmd = [self.module.get_bin_path('zfs')]
|
||||
|
||||
cmd.append('list')
|
||||
cmd.append(self.name)
|
||||
cmd = [self.module.get_bin_path('zfs'), 'list', self.name]
|
||||
|
||||
(rc, out, err) = self.module.run_command(cmd)
|
||||
|
||||
|
@ -188,10 +185,7 @@ class ZFSFacts(object):
|
|||
return False
|
||||
|
||||
def get_facts(self):
|
||||
cmd = [self.module.get_bin_path('zfs')]
|
||||
|
||||
cmd.append('get')
|
||||
cmd.append('-H')
|
||||
cmd = [self.module.get_bin_path('zfs'), 'get', '-H']
|
||||
if self.parsable:
|
||||
cmd.append('-p')
|
||||
if self.recurse:
|
||||
|
@ -202,10 +196,7 @@ class ZFSFacts(object):
|
|||
if self.type:
|
||||
cmd.append('-t')
|
||||
cmd.append(self.type)
|
||||
cmd.append('-o')
|
||||
cmd.append('name,property,value')
|
||||
cmd.append(self.properties)
|
||||
cmd.append(self.name)
|
||||
cmd.extend(['-o', 'name,property,value', self.properties, self.name])
|
||||
|
||||
(rc, out, err) = self.module.run_command(cmd)
|
||||
|
||||
|
|
|
@ -134,10 +134,7 @@ class ZPoolFacts(object):
|
|||
self.facts = []
|
||||
|
||||
def pool_exists(self):
|
||||
cmd = [self.module.get_bin_path('zpool')]
|
||||
|
||||
cmd.append('list')
|
||||
cmd.append(self.name)
|
||||
cmd = [self.module.get_bin_path('zpool'), 'list', self.name]
|
||||
|
||||
(rc, out, err) = self.module.run_command(cmd)
|
||||
|
||||
|
@ -147,10 +144,7 @@ class ZPoolFacts(object):
|
|||
return False
|
||||
|
||||
def get_facts(self):
|
||||
cmd = [self.module.get_bin_path('zpool')]
|
||||
|
||||
cmd.append('get')
|
||||
cmd.append('-H')
|
||||
cmd = [self.module.get_bin_path('zpool'), 'get', '-H']
|
||||
if self.parsable:
|
||||
cmd.append('-p')
|
||||
cmd.append('-o')
|
||||
|
|
|
@ -154,9 +154,7 @@ class BE(object):
|
|||
self.is_freebsd = os.uname()[0] == 'FreeBSD'
|
||||
|
||||
def _beadm_list(self):
|
||||
cmd = [self.module.get_bin_path('beadm')]
|
||||
cmd.append('list')
|
||||
cmd.append('-H')
|
||||
cmd = [self.module.get_bin_path('beadm'), 'list', '-H']
|
||||
if '@' in self.name:
|
||||
cmd.append('-s')
|
||||
return self.module.run_command(cmd)
|
||||
|
@ -218,42 +216,26 @@ class BE(object):
|
|||
return False
|
||||
|
||||
def activate_be(self):
|
||||
cmd = [self.module.get_bin_path('beadm')]
|
||||
|
||||
cmd.append('activate')
|
||||
cmd.append(self.name)
|
||||
|
||||
cmd = [self.module.get_bin_path('beadm'), 'activate', self.name]
|
||||
return self.module.run_command(cmd)
|
||||
|
||||
def create_be(self):
|
||||
cmd = [self.module.get_bin_path('beadm')]
|
||||
|
||||
cmd.append('create')
|
||||
cmd = [self.module.get_bin_path('beadm'), 'create']
|
||||
|
||||
if self.snapshot:
|
||||
cmd.append('-e')
|
||||
cmd.append(self.snapshot)
|
||||
|
||||
cmd.extend(['-e', self.snapshot])
|
||||
if not self.is_freebsd:
|
||||
if self.description:
|
||||
cmd.append('-d')
|
||||
cmd.append(self.description)
|
||||
|
||||
cmd.extend(['-d', self.description])
|
||||
if self.options:
|
||||
cmd.append('-o')
|
||||
cmd.append(self.options)
|
||||
cmd.extend(['-o', self.options])
|
||||
|
||||
cmd.append(self.name)
|
||||
|
||||
return self.module.run_command(cmd)
|
||||
|
||||
def destroy_be(self):
|
||||
cmd = [self.module.get_bin_path('beadm')]
|
||||
|
||||
cmd.append('destroy')
|
||||
cmd.append('-F')
|
||||
cmd.append(self.name)
|
||||
|
||||
cmd = [self.module.get_bin_path('beadm'), 'destroy', '-F', self.name]
|
||||
return self.module.run_command(cmd)
|
||||
|
||||
def is_mounted(self):
|
||||
|
@ -276,10 +258,7 @@ class BE(object):
|
|||
return False
|
||||
|
||||
def mount_be(self):
|
||||
cmd = [self.module.get_bin_path('beadm')]
|
||||
|
||||
cmd.append('mount')
|
||||
cmd.append(self.name)
|
||||
cmd = [self.module.get_bin_path('beadm'), 'mount', self.name]
|
||||
|
||||
if self.mountpoint:
|
||||
cmd.append(self.mountpoint)
|
||||
|
@ -287,9 +266,7 @@ class BE(object):
|
|||
return self.module.run_command(cmd)
|
||||
|
||||
def unmount_be(self):
|
||||
cmd = [self.module.get_bin_path('beadm')]
|
||||
|
||||
cmd.append('unmount')
|
||||
cmd = [self.module.get_bin_path('beadm'), 'unmount']
|
||||
if self.force:
|
||||
cmd.append('-f')
|
||||
cmd.append(self.name)
|
||||
|
|
Loading…
Reference in a new issue