mirror of
https://github.com/Rudd-O/ansible-qubes.git
synced 2025-03-01 14:22:33 +01:00
Bug fixes and add tests.
This commit is contained in:
parent
b74c21d028
commit
9bfc80d713
@ -16,7 +16,7 @@ UNDEFINED = object()
|
|||||||
|
|
||||||
class LookupModule(LookupBase):
|
class LookupModule(LookupBase):
|
||||||
|
|
||||||
def run(self, args, variables=None, vm=None, create=True, no_symbols=False, default=UNDEFINED):
|
def run(self, args, variables=None, vm=None, create=True, multiline=False, no_symbols=False, default=UNDEFINED):
|
||||||
|
|
||||||
ret = []
|
ret = []
|
||||||
|
|
||||||
@ -32,7 +32,9 @@ class LookupModule(LookupBase):
|
|||||||
display.vvvv(u"Password lookup using command %s" % cmd)
|
display.vvvv(u"Password lookup using command %s" % cmd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ret = subprocess.check_output(cmd)[:-1]
|
ret = subprocess.check_output(cmd)
|
||||||
|
if not multiline:
|
||||||
|
ret = ret[:-1]
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
if e.returncode == 8:
|
if e.returncode == 8:
|
||||||
if create or default is UNDEFINED:
|
if create or default is UNDEFINED:
|
||||||
@ -41,6 +43,4 @@ class LookupModule(LookupBase):
|
|||||||
else:
|
else:
|
||||||
raise AnsibleError("qubes-pass lookup failed: %s" % e)
|
raise AnsibleError("qubes-pass lookup failed: %s" % e)
|
||||||
|
|
||||||
if sys.version_info.major == 2:
|
return [ret]
|
||||||
return [ret]
|
|
||||||
return [ret.decode("utf-8")]
|
|
||||||
|
42
lookup_plugins/test-qubes-pass.yml
Normal file
42
lookup_plugins/test-qubes-pass.yml
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
- hosts: localhost
|
||||||
|
gather_facts: no
|
||||||
|
tasks:
|
||||||
|
- name: delete
|
||||||
|
shell: |
|
||||||
|
qvm-pass rm test-qubes-pass || true
|
||||||
|
|
||||||
|
- name: test qubes-pass lookup
|
||||||
|
shell: |
|
||||||
|
password={{ lookup("qubes-pass", "test-qubes-pass") | quote }}
|
||||||
|
echo "$password"
|
||||||
|
register: firsttry
|
||||||
|
- name: test qubes-pass lookup second time
|
||||||
|
shell: |
|
||||||
|
password={{ lookup("qubes-pass", "test-qubes-pass") | quote }}
|
||||||
|
echo "$password"
|
||||||
|
register: secondtry
|
||||||
|
- name: evaluate if they match
|
||||||
|
shell: |
|
||||||
|
firsttry={{ firsttry.stdout | quote }}
|
||||||
|
secondtry={{ secondtry.stdout | quote }}
|
||||||
|
if [ "$firsttry" != "$secondtry" ] ; then echo no match ; exit 8 ; fi
|
||||||
|
- name: delete
|
||||||
|
shell: qvm-pass rm test-qubes-pass
|
||||||
|
|
||||||
|
- name: generate randomness
|
||||||
|
shell: |
|
||||||
|
pwd
|
||||||
|
dd if=/dev/urandom of=.randomdata bs=16384 count=1
|
||||||
|
- name: test qubes-pass insert
|
||||||
|
shell: |
|
||||||
|
qvm-pass insert -m test-qubes-pass < .randomdata
|
||||||
|
- name: evaluate if they match
|
||||||
|
shell: |
|
||||||
|
set -e
|
||||||
|
echo {{ lookup("qubes-pass", "test-qubes-pass", create=False, multiline=True) | b64encode | quote }} | base64 -d > .randomdatafetched
|
||||||
|
ls -la .randomdata .randomdatafetched
|
||||||
|
diff .randomdata .randomdatafetched
|
||||||
|
- name: delete
|
||||||
|
shell: |
|
||||||
|
qvm-pass rm test-qubes-pass
|
||||||
|
rm -f .randomdata .randomdatafetched
|
Loading…
x
Reference in New Issue
Block a user