Repository: ansible/ansible

Issue:
ERROR! Unexpected Exception, this is probably a bug: 'AnsibleSequence' object has no attribute 'strip'
##### ISSUE TYPE

- Bug

##### COMPONENT NAME
ansible module "import_playbook"

##### ANSIBLE VERSION
```
ansible --version
ansible 2.4.3.0
  config file = None
  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, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

```

##### CONFIGURATION
No settings changed, confirmed with "ansible-config dump --only-changed" outputting nothing.

##### OS / ENVIRONMENT
```
cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 
uname -a
Linux 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25 20:13:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
```
##### SUMMARY
Exception when running playbook: "ERROR! Unexpected Exception, this is probably a bug: 'AnsibleSequence' object has no attribute 'strip'"

##### STEPS TO REPRODUCE

1. Create a playbook. I created one that just prints a debug message and nothing else.
2. Attempt to run the playbook with ansible-playbook --inventory-file=/path/to/inventory -vvv test.yml

```
- hosts: all
  become: yes
  gather_facts: no

  tasks:
    - name: print debug msg
      debug:
        msg: 'Hello, World!'
- import_playbook:
    - common/main.yml
    - syslog/main.yml
    - ntp/main.yml
    - resolv/main.yml
    - audit/main.yml

```

##### EXPECTED RESULTS
That the play run with all included playbook

##### ACTUAL RESULTS
```
ERROR! Unexpected Exception, this is probably a bug: 'AnsibleSequence' object has no attribute 'strip'
the full traceback was:

Traceback (most recent call last):
  File "/usr/bin/ansible-playbook", line 106, in <module>
    exit_code = cli.run()
  File "/usr/lib/python2.7/site-packages/ansible/cli/playbook.py", line 122, in run
    results = pbex.run()
  File "/usr/lib/python2.7/site-packages/ansible/executor/playbook_executor.py", line 82, in run
    pb = Playbook.load(playbook_path, variable_manager=self._variable_manager, loader=self._loader)
  File "/usr/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 54, in load
    pb._load_playbook_data(file_name=file_name, variable_manager=variable_manager)
  File "/usr/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 99, in _load_playbook_data
    pb = PlaybookInclude.load(entry, basedir=self._basedir, variable_manager=variable_manager, loader=self._loader)
  File "/usr/lib/python2.7/site-packages/ansible/playbook/playbook_include.py", line 43, in load
    return PlaybookInclude().load_data(ds=data, basedir=basedir, variable_manager=variable_manager, loader=loader)
  File "/usr/lib/python2.7/site-packages/ansible/playbook/playbook_include.py", line 58, in load_data
    new_obj = super(PlaybookInclude, self).load_data(ds, variable_manager, loader)
  File "/usr/lib/python2.7/site-packages/ansible/playbook/base.py", line 245, in load_data
    ds = self.preprocess_data(ds)
  File "/usr/lib/python2.7/site-packages/ansible/playbook/playbook_include.py", line 118, in preprocess_data
    self._preprocess_import(ds, new_ds, k, v)
  File "/usr/lib/python2.7/site-packages/ansible/playbook/playbook_include.py", line 141, in _preprocess_import
    items = split_args(v)
  File "/usr/lib/python2.7/site-packages/ansible/parsing/splitter.py", line 161, in split_args
    args = args.strip()
AttributeError: 'AnsibleSequence' object has no attribute 'strip'


```



Discussion:
Files identified in the description:
* [lib/ansible/modules/utilities/logic/import_playbook.py](https://github.com/ansible/ansible/blob/devel/lib/ansible/modules/utilities/logic/import_playbook.py)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
The cause to this is that `import_playbook` only accepts a single string identifying a single playbook.  It does not accept a list of playbooks.

I'll leave this open as the traceback is still a bug.
Yeah, confirm that selecting only one playbook solved the issed.
I've tried before commenting the other, like this:
```
- import_playbook:
    #- common/main.yml
    #- syslog/main.yml
    #- ntp/main.yml
    #- resolv/main.yml
    - audit/main.yml
```
But it doesn't work anyways. Then I modified the playbook by this way and it worked:
```
- import_playbook:  common/main.yml
```

Thanks
Red


Resolving patch:
diff --git a/lib/ansible/playbook/playbook_include.py b/lib/ansible/playbook/playbook_include.py
--- a/lib/ansible/playbook/playbook_include.py
+++ b/lib/ansible/playbook/playbook_include.py
@@ -21,8 +21,8 @@
 
 import os
 
-from ansible.errors import AnsibleParserError, AnsibleError, AnsibleAssertionError
-from ansible.module_utils.six import iteritems
+from ansible.errors import AnsibleParserError, AnsibleAssertionError
+from ansible.module_utils.six import iteritems, string_types
 from ansible.parsing.splitter import split_args, parse_kv
 from ansible.parsing.yaml.objects import AnsibleBaseYAMLObject, AnsibleMapping
 from ansible.playbook.attribute import FieldAttribute
@@ -135,6 +135,8 @@ def _preprocess_import(self, ds, new_ds, k, v):
 
         if v is None:
             raise AnsibleParserError("playbook import parameter is missing", obj=ds)
+        elif not isinstance(v, string_types):
+            raise AnsibleParserError("playbook import parameter must be a string indicating a file path, got %s instead" % type(v), obj=ds)
 
         # The import_playbook line must include at least one item, which is the filename
         # to import. Anything after that should be regarded as a parameter to the import


Test patch: