Repository: ansible/ansible

Issue:
Cyberark plugin fails with 'list' object has no attribute 'split'"
##### Summary

Cyberark plugin fails with 'list' object has no attribute 'split'"

##### COMPONENT NAME
cyperarkpassword.py lookup plugin

##### Environment

* Ansible version:  2.4.0

##### Steps To Reproduce:
1. Create a new playbook calling the cyberarkpassword.py lookup plugin
-- Sample playbook:
```
---
- name: sanity-check
  hosts: all
  gather_facts: false
  vars:
    aimquery:
      appid: "XXX_XXX_XXX"
      query: "safe=*;folder=root;username=root;hostname={{ inventory_hostname }}"
      output: "PassProps.UserName,Password,PassProps.Address,PasswordChangeInProcess"
    password_object: "{{lookup('cyberarkpassword',aimquery) }}"
    ansible_user: "{{ password_object[0].passprops.username }}"
    ansible_ssh_pass: "{{ password_object[0].password }}"
  tasks:
  - debug:
      var: aimquery
  - shell: ls /root
```
2. Run playbook that calls the plugin

##### Expected Results:

Playbook runs successfully

##### Actual Results:

Error:
```
  "{{lookup('cyberarkpassword',aimquery) }}: An unhandled exception occurred while running the lookup plugin 'cyberarkpassword'. Error was a <type 'exceptions.AttributeError'>, original message: 'list' object has no attribute 'split'"
```
##### Additional Information:

Filing as upstream issue for ansible/ansible-tower#7903
Commenting out the following line in cyberarkpassword.py resolves this issue so it can be ran successfully in Tower:
https://github.com/ansible/ansible/blob/devel/lib/ansible/plugins/lookup/cyberarkpassword.py#L170


Discussion:
@msilmser Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information. 

Here are the items we could not find in your description:
- component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: issue_missing_data --->
For Ansible Tower support or questions, please utilize https://access.redhat.com/products/ansible-tower-red-hat

For the Open source version (AWX) https://github.com/ansible/awx

This issue tracker is for the open source Ansible CLI tools project.
This is not a tower issue. The cyberark maintainers need to correct an issue in the lookup plugin.
Tagging Cyberark contacts:

@cyberark-bizdev 
ah, took the title literally since reporter said it worked in cli but not in tower
I just tested your sample playbook in 2.4.0 and it worked fine for me. 

Could you please share the output of:  
ansible --version

Mine shows as:
ansible 2.4.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov  6 2016, 00:28:07) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

I am particularly interested in the version of python you are using

The issue only arises when supplying `-vvvv` on the CLI.  The is due to the following line:

https://github.com/ansible/ansible/blob/24d4787b2d3bf531c048fe3cdce0534180193475/lib/ansible/plugins/lookup/cyberarkpassword.py#L170
I see the issue now... updating the line to pass a string to display.vvvv

Resolving patch:
diff --git a/lib/ansible/plugins/lookup/cyberarkpassword.py b/lib/ansible/plugins/lookup/cyberarkpassword.py
--- a/lib/ansible/plugins/lookup/cyberarkpassword.py
+++ b/lib/ansible/plugins/lookup/cyberarkpassword.py
@@ -167,7 +167,7 @@ class LookupModule(LookupBase):
 
     def run(self, terms, variables=None, **kwargs):
 
-        display.vvvv(terms)
+        display.vvvv("%s" % terms)
         if isinstance(terms, list):
             return_values = []
             for term in terms:


Test patch: