diff --git a/README.md b/README.md index df135c2..c46920d 100644 --- a/README.md +++ b/README.md @@ -63,14 +63,14 @@ To install from [GitHub](https://github.com/OneIdentity/ansible-privilege-manage Using `ansible-galaxy` command: ```bash -ansible-galaxy collection install https://github.com/OneIdentity/ansible-privilege-manager/releases/download/v0.0.1/oneidentity-privilege_manager-0.0.1.tar.gz +ansible-galaxy collection install https://github.com/OneIdentity/ansible-privilege-manager/releases/download/v0.0.2/oneidentity-privilege_manager-0.0.2.tar.gz ``` The collection can also be added to a project's `requirements.yml` file ```yaml --- collections: - - name: https://github.com/OneIdentity/ansible-privilege-manager/releases/download/v0.0.1/oneidentity-privilege_manager-0.0.1.tar.gz + - name: https://github.com/OneIdentity/ansible-privilege-manager/releases/download/v0.0.2/oneidentity-privilege_manager-0.0.2.tar.gz ``` and installed using the `ansible-galaxy` command. This method allows all required collections for a project to be specified in one place and installed with one command. @@ -100,7 +100,7 @@ For local build and installation, you can clone the Git repository, build the co The build command will generate an Ansible Galaxy collection artifact with a `tar.gz` file extension, sample output will look like the following: ``` - Created collection for oneidentity.privilege_manager at /home/user/ansible-privilege-manager/oneidentity-privilege_manager-0.0.1.tar.gz + Created collection for oneidentity.privilege_manager at /home/user/ansible-privilege-manager/oneidentity-privilege_manager-0.0.2.tar.gz ``` `Pleae note the path shown above is just an example, the path to your build artifact will be in the root directory of the cloned repository.` @@ -110,14 +110,14 @@ For local build and installation, you can clone the Git repository, build the co Using `ansible-galaxy` command: ```bash - ansible-galaxy collection install /home/user/ansible-privilege-manager/oneidentity-privilege_manager-0.0.1.tar.gz + ansible-galaxy collection install /home/user/ansible-privilege-manager/oneidentity-privilege_manager-0.0.2.tar.gz ``` The collection can also be added to a project's `requirements.yml` file ```yaml --- collections: - - name: /home/user/ansible-privilege-manager/oneidentity-privilege_manager-0.0.1.tar.gz + - name: /home/user/ansible-privilege-manager/oneidentity-privilege_manager-0.0.2.tar.gz ``` and installed using the `ansible-galaxy` command. This method allows all required collections for a project to be specified in one place and installed with one command. diff --git a/galaxy.yml b/galaxy.yml index 5c74e75..e046ab7 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -10,7 +10,7 @@ namespace: oneidentity name: privilege_manager # Semantic versioning compliant version designation -version: "0.0.1" +version: "0.0.2" # The path do the Markdown(.md) readme file readme: README.md diff --git a/plugins/module_utils/check_file_exec.py b/plugins/module_utils/check_file_exec.py index ff9530d..9743fd8 100644 --- a/plugins/module_utils/check_file_exec.py +++ b/plugins/module_utils/check_file_exec.py @@ -71,9 +71,12 @@ def get_file_version(file_path, version_cmd): # Exec file to get version try: - rval_bytes = subprocess.check_output(' '.join(cmd), stderr=subprocess.STDOUT, shell=True) + p = subprocess.Popen(' '.join(cmd), stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + rval_bytes, rval_err = p.communicate() + rval_bytes += rval_err except subprocess.CalledProcessError as e: rval_bytes = e.output + # Popen returns list of bytes so we have to decode to get a string rval_str = rval_bytes.decode(sys.stdout.encoding) # Compile regex diff --git a/plugins/module_utils/pmjoin.py b/plugins/module_utils/pmjoin.py index 11d0243..2811845 100644 --- a/plugins/module_utils/pmjoin.py +++ b/plugins/module_utils/pmjoin.py @@ -98,12 +98,14 @@ def pmjoin_status(): # Call pm*info try: - rval_bytes = subprocess.check_output(' '.join(cmd), stderr=subprocess.STDOUT, shell=True) + p = subprocess.Popen(' '.join(cmd), stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + rval_bytes, rval_err = p.communicate() + rval_bytes += rval_err # This exception happens when the process exits with a non-zero return code except subprocess.CalledProcessError as e: # Just grab output bytes likes a normal exit, we'll parse it for errors anyway rval_bytes = e.output - # check_output returns list of bytes so we have to decode to get a string + # Popen returns list of bytes so we have to decode to get a string rval_str = rval_bytes.decode(sys.stdout.encoding) # Parse vastool return diff --git a/plugins/modules/pmjoin.py b/plugins/modules/pmjoin.py index 039dde7..8ad5db1 100644 --- a/plugins/modules/pmjoin.py +++ b/plugins/modules/pmjoin.py @@ -133,6 +133,7 @@ from ansible.module_utils.basic import AnsibleModule import sys import subprocess +import traceback import re import ansible_collections.oneidentity.privilege_manager.plugins.module_utils.pmjoin as pmj @@ -246,17 +247,23 @@ def run_normal(params, result): facts_verbose = params['facts_verbose'] facts_key = params['facts_key'] if params['facts_key'] else FACTS_KEY_DEFAULT - # Check pmjoin - err, pmjoin_path, pminfo_path, pmjoin_version = pmj.pmjoin_find() + try: + + # Check pmjoin + err, pmjoin_path, pminfo_path, pmjoin_version = pmj.pmjoin_find() + + # Run pmjoin + if err is None: + err, changed, output = run_pmjoin( + pmjoin_path, + state, + server, + password, + extra_args) - # Run pmjoin - if err is None: - err, changed, output = run_pmjoin( - pmjoin_path, - state, - server, - password, - extra_args) + except Exception: + tb = traceback.format_exc() + err = str(tb) # Build result result['changed'] = changed @@ -351,18 +358,20 @@ def run_pmjoin_join( cmd += [path] cmd += ['-b'] cmd += ['-a'] - # cmd += ['-q'] + cmd += ['-q'] cmd += [server] cmd += [extra_args] if extra_args else [] # Call vastool try: - rval_bytes = subprocess.check_output(' '.join(cmd), stderr=subprocess.STDOUT, shell=True) + p = subprocess.Popen(' '.join(cmd), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + rval_bytes, rval_err = p.communicate(password) + rval_bytes += rval_err # This exception happens when the process exits with a non-zero return code except subprocess.CalledProcessError as e: # Just grab output bytes likes a normal exit, we'll parse it for errors anyway rval_bytes = e.output - # check_output returns list of bytes so we have to decode to get a string + # Popen returns list of bytes so we have to decode to get a string rval_str = rval_bytes.decode(sys.stdout.encoding) # Parse pmjoin return @@ -392,12 +401,14 @@ def run_pmjoin_unjoin( # Call vastool try: - rval_bytes = subprocess.check_output(' '.join(cmd), stderr=subprocess.STDOUT, shell=True) + p = subprocess.Popen(' '.join(cmd), stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + rval_bytes, rval_err = p.communicate() + rval_bytes += rval_err # This exception happens when the process exits with a non-zero return code except subprocess.CalledProcessError as e: # Just grab output bytes likes a normal exit, we'll parse it for errors anyway rval_bytes = e.output - # check_output returns list of bytes so we have to decode to get a string + # Popen returns list of bytes so we have to decode to get a string rval_str = rval_bytes.decode(sys.stdout.encoding) # Parse pmjoin return diff --git a/plugins/modules/preflight.py b/plugins/modules/preflight.py index b95985e..9220511 100644 --- a/plugins/modules/preflight.py +++ b/plugins/modules/preflight.py @@ -136,6 +136,7 @@ from ansible.module_utils.basic import AnsibleModule import sys +import traceback import subprocess import ansible_collections.oneidentity.privilege_manager.plugins.module_utils.check_file_exec as cfe @@ -258,17 +259,23 @@ def run_normal(params, result): facts_key = params['facts_key'] if params['facts_key'] else FACTS_KEY_DEFAULT path = params['path'] if params['path'] else PATH_DEFAULT - # Check preflight - err, version = cfe.check_file_exec(path, '-v') + try: + + # Check preflight + err, version = cfe.check_file_exec(path, '-v') + + # Run preflight + if err is None: + err, steps = run_preflight( + mode, + server, + verbose, + extra_args, + path) - # Run preflight - if err is None: - err, steps = run_preflight( - mode, - server, - verbose, - extra_args, - path) + except Exception: + tb = traceback.format_exc() + err = str(tb) # Build result result['changed'] = False # preflight never makes any changes to the host @@ -314,12 +321,14 @@ def run_preflight( # Call preflight try: - rval_bytes = subprocess.check_output(' '.join(cmd), stderr=subprocess.STDOUT, shell=True) + p = subprocess.Popen(' '.join(cmd), stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + rval_bytes, rval_err = p.communicate() + rval_bytes += rval_err # This exception happens when the process exits with a non-zero return code except subprocess.CalledProcessError as e: # Just grab output bytes likes a normal exit, we'll parse it for errors anyway rval_bytes = e.output - # check_output returns list of bytes so we have to decode to get a string + # Popen returns list of bytes so we have to decode to get a string rval_str = rval_bytes.decode(sys.stdout.encoding) # Parse preflight return diff --git a/plugins/modules/software_pkgs.py b/plugins/modules/software_pkgs.py index d909815..07b1ca9 100644 --- a/plugins/modules/software_pkgs.py +++ b/plugins/modules/software_pkgs.py @@ -126,6 +126,7 @@ from ansible.module_utils.basic import AnsibleModule import os +import traceback import glob import re @@ -300,23 +301,29 @@ def run_normal(params, result): facts = params['facts'] facts_key = params['facts_key'] if params['facts_key'] else FACTS_KEY_DEFAULT - # Check directory - err = check_dir(path) + try: - # Check mode - err, sub_dirs = check_mode(mode) + # Check directory + err = check_dir(path) - # Find packages - if err is None: - for sub_dir in sub_dirs: - err, p = find_packages(path, sub_dir, sys, dist, arch) - if err is None: - packages.update(p) - else: - break - - if not err and not packages: - err = 'No packages found for sys=' + sys + ', dist=' + dist + ', arch=' + arch + # Check mode + err, sub_dirs = check_mode(mode) + + # Find packages + if err is None: + for sub_dir in sub_dirs: + err, p = find_packages(path, sub_dir, sys, dist, arch) + if err is None: + packages.update(p) + else: + break + + if not err and not packages: + err = 'No packages found for sys=' + sys + ', dist=' + dist + ', arch=' + arch + + except Exception: + tb = traceback.format_exc() + err = str(tb) # Build result result['changed'] = False # Never makes any changes to the host diff --git a/roles/common/vars/main.yml b/roles/common/vars/main.yml index f4e4c56..0cc3549 100644 --- a/roles/common/vars/main.yml +++ b/roles/common/vars/main.yml @@ -1,3 +1,3 @@ --- -collection_version: '0.0.1' +collection_version: '0.0.2' diff --git a/roles/join/tasks/pmjoin.yml b/roles/join/tasks/pmjoin.yml index 6af0815..933cd50 100644 --- a/roles/join/tasks/pmjoin.yml +++ b/roles/join/tasks/pmjoin.yml @@ -16,4 +16,4 @@ # Fail if there was a message returned - fail: msg: "{{ result.msg }}" - when: result.msg + when: result.msg is defined and result.msg diff --git a/roles/preflight/tasks/utils/package_copy.yml b/roles/preflight/tasks/utils/package_copy.yml index 2ff193e..db39c94 100644 --- a/roles/preflight/tasks/utils/package_copy.yml +++ b/roles/preflight/tasks/utils/package_copy.yml @@ -8,3 +8,8 @@ mode: 'u+rwx' ignore_errors: true changed_when: false + register: rval + +- fail: + msg: "{{ rval.msg }}" + when: rval.msg is defined and rval.msg diff --git a/roles/preflight/tasks/utils/temp_dir_delete.yml b/roles/preflight/tasks/utils/temp_dir_delete.yml index 6d764a6..bbf7882 100644 --- a/roles/preflight/tasks/utils/temp_dir_delete.yml +++ b/roles/preflight/tasks/utils/temp_dir_delete.yml @@ -7,3 +7,8 @@ state: absent ignore_errors: true changed_when: false + register: rval + +- fail: + msg: "{{ rval.msg }}" + when: rval.msg is defined and rval.msg diff --git a/roles/software/tasks/check_package_directory.yml b/roles/software/tasks/check_package_directory.yml index c636f83..2d874d5 100644 --- a/roles/software/tasks/check_package_directory.yml +++ b/roles/software/tasks/check_package_directory.yml @@ -17,4 +17,4 @@ - fail: msg: "{{ software_pkgs.msg }}" register: result - when: software_pkgs.msg + when: software_pkgs.msg is defined and software_pkgs.msg diff --git a/roles/software/tasks/temp_dir_create.yml b/roles/software/tasks/temp_dir_create.yml index ebe67f7..3d929be 100644 --- a/roles/software/tasks/temp_dir_create.yml +++ b/roles/software/tasks/temp_dir_create.yml @@ -11,4 +11,4 @@ - fail: msg: "{{ result.msg }}" - when: result.failed + when: result.failed is defined and result.failed diff --git a/roles/software/tasks/temp_dir_delete.yml b/roles/software/tasks/temp_dir_delete.yml index d0d95b0..0a359a1 100644 --- a/roles/software/tasks/temp_dir_delete.yml +++ b/roles/software/tasks/temp_dir_delete.yml @@ -11,4 +11,4 @@ - fail: msg: "{{ result.msg }}" - when: result.failed + when: result.failed is defined and result.failed diff --git a/roles/software/tasks/utils/package_copy.yml b/roles/software/tasks/utils/package_copy.yml index aa068b4..589c050 100644 --- a/roles/software/tasks/utils/package_copy.yml +++ b/roles/software/tasks/utils/package_copy.yml @@ -7,3 +7,8 @@ dest: "{{ package_dest }}" ignore_errors: true changed_when: false + register: rval + +- fail: + msg: "{{ rval.msg }}" + when: rval.msg is defined and rval.msg