Doubts using local_action, module, and with_items all together

1,011 views
Skip to first unread message

Helio Campos Mello de Andrade

unread,
Oct 3, 2017, 4:36:29 PM10/3/17
to Ansible Project
Hi guys,

 - I looked for many places but could not find an answer of why this could be happening. I have the following play and its giving lots of headaches:

Environment:

$ uname -v
#39~16.04.1-Ubuntu SMP Wed Sep 13 09:02:42 UTC 2017
uname -r
4.10.0-35-generic
$ pip freeze | grep ansible
ansible==2.5.0
ansible-lint==3.4.16
$ python --version
Python 2.7.12+

Code being tested:

---

- name: Base | Deploy
  hosts: deploy
  become: true
  vars:
    application_vars__repository_url: 'MY_REPOSITORY_URL'
    application_vars__branch_name: 'MY_BRANCH_NAME'
  tasks:
  - name: Application | Defining local temporary directory
    become: false
    local_action:
      module: tempfile
      state: directory
    register: local_temp_file

  - name: Application | Download the source code locally
    become: false
    local_action:
      module: git
      repo: '{{ application_vars__repository_url }}'
      remote: '{{ application_vars__branch_name }}'
      dest: '{{ local_temp_file.path }}'
      depth: 1
      force: yes

  - name: Application | Remove git files
    become: false
    local_action:
      module:
        file:
        path: '{{ local_temp_file.path }}/{{ item }}'
        state: absent
        recurse: yes
      with_items:
        - 'docker-compose.yml'
        - 'Dockerfile'
        - '.dockerignore'
        - '.git'
        - '.gitignore'
        - '.gitmodules'
        - 'README.md'
        - 'spec'
        - 'tests_output'
        - '.travis.yml'

This code is actually inside a role that installs the application and removes unnecessary files thats why I have "becomes" defined as "true" in the global play and "false" in the specific tasks. Its also why I have "local_action" defines on those tasks. It does not matter if I define the git variables or not, the parsing still gives this error:

ansible-playbook -i inventory/hosts deploy2.yml -vvv
ansible-playbook 2.5.0
  config file = /home/deploy/projects/XXXXXXXX/ansible.cfg
  configured module search path = [u'/home/deploy/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible
  executable location = /home/deploy/.virtualenvs/ansible/bin/ansible-playbook
  python version = 2.7.12+ (default, Sep 17 2016, 12:08:02) [GCC 6.2.0 20160914]
Using /home/deploy/projects/XXXXXXXX/ansible.cfg as config file
Parsed /home/deploy/projects/XXXXXXXX/inventory/hosts inventory source with ini plugin
ERROR! Unexpected Exception, this is probably a bug: 'AnsibleMapping' object has no attribute 'strip'
the full traceback was:

Traceback (most recent call last):
  File "/home/deploy/.virtualenvs/ansible/bin/ansible-playbook", line 109, in <module>
    exit_code = cli.run()
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/cli/playbook.py", line 130, in run
    results = pbex.run()
  File "/home/deploy/.virtualenvs/ansible/local/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 "/home/deploy/.virtualenvs/ansible/local/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 "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 106, in _load_playbook_data
    entry_obj = Play.load(entry, variable_manager=variable_manager, loader=self._loader)
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/play.py", line 112, in load
    return p.load_data(data, variable_manager=variable_manager, loader=loader)
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/base.py", line 254, in load_data
    self._attributes[name] = method(name, ds[name])
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/play.py", line 142, in _load_tasks
    return load_list_of_blocks(ds=ds, play=self, variable_manager=self._variable_manager, loader=self._loader)
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/helpers.py", line 59, in load_list_of_blocks
    loader=loader,
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/block.py", line 86, in load
    return b.load_data(data, variable_manager=variable_manager, loader=loader)
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/base.py", line 254, in load_data
    self._attributes[name] = method(name, ds[name])
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/block.py", line 122, in _load_block
    use_handlers=self._use_handlers,
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/helpers.py", line 342, in load_list_of_tasks
    t = Task.load(task_ds, block=block, role=role, task_include=task_include, variable_manager=variable_manager, loader=loader)
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/task.py", line 138, in load
    return t.load_data(data, variable_manager=variable_manager, loader=loader)
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/base.py", line 244, in load_data
    ds = self.preprocess_data(ds)
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/playbook/task.py", line 178, in preprocess_data
    (action, args, delegate_to) = args_parser.parse()
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/parsing/mod_args.py", line 286, in parse
    action, args = self._normalize_parameters(thing, action=action, additional_args=additional_args)
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/parsing/mod_args.py", line 164, in _normalize_parameters
    (action, args) = self._normalize_old_style_args(thing)
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/parsing/mod_args.py", line 236, in _normalize_old_style_args
    action, module_args = self._split_module_string(thing['module'])
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/parsing/mod_args.py", line 112, in _split_module_string
    tokens = split_args(module_string)
  File "/home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible/parsing/splitter.py", line 161, in split_args
    args = args.strip()
AttributeError: 'AnsibleMapping' object has no attribute 'strip'

I know that tried to put the "with_items" indented with the "local_action:", the "module", and as an argument for module but all of them gives me the same error.

What am I doing wrong? Can't I use the "with_items" in any level of this task when I use local_action and module?

Best regards,

Brian Coca

unread,
Oct 3, 2017, 4:54:45 PM10/3/17
to Ansible Project
with_items is a task keyword, not a module option, 'outdent' it to
match local_action




--
----------
Brian Coca

Helio Campos Mello de Andrade

unread,
Oct 3, 2017, 5:33:12 PM10/3/17
to Ansible Project
Hi Brian,

 - First of all, thanks for the fast response. I've made what you asked:

    - 'Dockerfile.alpine'
    - '.dockerignore'
    - '.editorconfig'
    - '.env.sample'
    - '.git'
    - '.gitignore'
    - '.gitmodules'
    - 'network_design.md'
    - 'rails-server.yml'
    - 'README.md'
    - '.rspec'
    - '.rubocop.yml'
    - 'spec'
    - 'TESTES.md'
    - 'tests_output'
    - '.travis.yml'

But I still get the same results:

ansible-playbook -i inventory/hosts deploy2.yml -vvv
ERROR! Unexpected Exception, this is probably a bug: 'AnsibleMapping' object has no attribute 'strip'
ansible-playbook 2.5.0
  config file = /home/deploy/projects/########/ansible.cfg
  configured module search path = [u'/home/deploy/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/deploy/.virtualenvs/ansible/local/lib/python2.7/site-packages/ansible
  executable location = /home/deploy/.virtualenvs/ansible/bin/ansible-playbook
  python version = 2.7.12+ (default, Sep 17 2016, 12:08:02) [GCC 6.2.0 20160914]
Using /home/deploy/projects/########/ansible.cfg as config file
Parsed /home/deploy/projects/########/inventory/hosts inventory source with ini plugin

Brian Coca

unread,
Oct 3, 2017, 5:39:45 PM10/3/17
to Ansible Project
you are also incorrectly indenting all the options for file and you
have both module: and file: ... which does not seem as what you wanted
to do.





--
----------
Brian Coca

Helio Campos Mello de Andrade

unread,
Oct 4, 2017, 8:21:59 AM10/4/17
to Ansible Project
Hi Brian,

 - You were right. I've made these changes and it worked.

Reply all
Reply to author
Forward
0 new messages