Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using include within an included role from within a role results in AttributeError #27345

Closed
mtnbikenc opened this issue Jul 26, 2017 · 0 comments · Fixed by #27718
Closed

Using include within an included role from within a role results in AttributeError #27345

mtnbikenc opened this issue Jul 26, 2017 · 0 comments · Fixed by #27718
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. c:playbook/role_include c:playbook/task_include P2 Priority 2 - Issue Blocks Release support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@mtnbikenc
Copy link
Contributor

mtnbikenc commented Jul 26, 2017

ISSUE TYPE
  • Bug Report
COMPONENT NAME
  • role + include_role + include
ANSIBLE VERSION
ansible 2.4.0 (devel d19b4f2977) last updated 2017/07/26 13:45:18 (GMT -400)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/rteague/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/rteague/dev/clusters/aws-c2/ansible/lib/ansible
  executable location = /home/rteague/dev/clusters/aws-c2/ansible/bin/ansible
  python version = 2.7.13 (default, Jun 26 2017, 10:20:05) [GCC 7.1.1 20170622 (Red Hat 7.1.1-3)]
CONFIGURATION
OS / ENVIRONMENT
  • N/A
SUMMARY

When running the playbooks defined below, an AttributeError exception is created when unable to parse the path.

  • playbook calls role
  • role calls include_role
  • included role calls include
STEPS TO REPRODUCE
ansible-playbook -i localhost, playbook.yml -vvvv 

File organization

tree .
.
├── playbook.yml
└── roles
    ├── test
    │   └── tasks
    │       └── main.yml
    └── test-1
        └── tasks
            ├── included_file.yml
            └── main.yml

5 directories, 4 files

playbook.yml

- name: Test Playbook
  hosts: localhost
  connection: local
  gather_facts: no

  roles:
    - test

roles/test/tasks/main.yml

---
- include_role:
    name: test-1
  vars:
    some_file: included_file

roles/test-1/tasks/main.yml

---
- name: Include some task file
  include: "{{ some_file }}.yml"

roles/test-1/tasks/included_file.yml

---
  - debug:
      msg: "included file"
EXPECTED RESULTS

Expect the debug task in included_file.yml to run.

ACTUAL RESULTS
$ ansible-playbook -i localhost, playbook.yml -vvvv                                                                                        
ansible-playbook 2.4.0 (devel d19b4f2977) last updated 2017/07/26 13:45:18 (GMT -400)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/rteague/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/rteague/dev/clusters/aws-c2/ansible/lib/ansible
  executable location = /home/rteague/dev/clusters/aws-c2/ansible/bin/ansible-playbook
  python version = 2.7.13 (default, Jun 26 2017, 10:20:05) [GCC 7.1.1 20170622 (Red Hat 7.1.1-3)]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Set default localhost to localhost
Parsed localhost, inventory source with host_list plugin
[DEPRECATION WARNING]: The use of 'include' for tasks has been deprecated. Use 'import_tasks' for static inclusions or 'include_tasks' for 
dynamic inclusions.
This feature will be removed in a future release. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
Loading callback plugin default of type stdout, v2.0 from /home/rteague/dev/clusters/aws-c2/ansible/lib/ansible/plugins/callback/__init__.pyc

PLAYBOOK: playbook.yml ***********************************************************************************************************************
1 plays in playbook.yml

PLAY [Test Playbook] *************************************************************************************************************************
META: ran handlers

TASK [test-1 : Include some task file] *******************************************************************************************************
task path: /home/rteague/dev/clusters/aws-c2/reproducer/roles/test-1/tasks/main.yml:3
ERROR! Unexpected Exception, this is probably a bug: 'NoneType' object has no attribute 'rfind'
the full traceback was:

Traceback (most recent call last):
  File "/home/rteague/dev/clusters/aws-c2/ansible/bin/ansible-playbook", line 106, in <module>
    exit_code = cli.run()
  File "/home/rteague/dev/clusters/aws-c2/ansible/lib/ansible/cli/playbook.py", line 130, in run
    results = pbex.run()
  File "/home/rteague/dev/clusters/aws-c2/ansible/lib/ansible/executor/playbook_executor.py", line 153, in run
    result = self._tqm.run(play=play)
  File "/home/rteague/dev/clusters/aws-c2/ansible/lib/ansible/executor/task_queue_manager.py", line 289, in run
    play_return = strategy.run(iterator, play_context)
  File "/home/rteague/dev/clusters/aws-c2/ansible/lib/ansible/plugins/strategy/linear.py", line 333, in run
    variable_manager=self._variable_manager
  File "/home/rteague/dev/clusters/aws-c2/ansible/lib/ansible/playbook/included_file.py", line 106, in process_include_results
    parent_include_dir = os.path.dirname(parent_include._role_path)
  File "/usr/lib64/python2.7/posixpath.py", line 122, in dirname
    i = p.rfind('/') + 1
AttributeError: 'NoneType' object has no attribute 'rfind'

Here is output with Ansible 2.3.1

ansible 2.3.1.0
  config file = /home/rteague/dev/clusters/aws-c2/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.13 (default, Jun 26 2017, 10:20:05) [GCC 7.1.1 20170622 (Red Hat 7.1.1-3)]
$ ansible-playbook -i localhost, playbook.yml -vvvv                                                                                        
Using /etc/ansible/ansible.cfg as config file
Set default localhost to localhost
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/__init__.pyc

PLAYBOOK: playbook.yml ***********************************************************************************************************************
1 plays in playbook.yml

PLAY [Test Playbook] *************************************************************************************************************************
META: ran handlers

TASK [test-1 : Include some task file] *******************************************************************************************************
task path: /home/rteague/dev/clusters/aws-c2/reproducer/roles/test-1/tasks/main.yml:3
included: /home/rteague/dev/clusters/aws-c2/reproducer/roles/test-1/tasks/included_file.yml for localhost

TASK [test-1 : debug] ************************************************************************************************************************
task path: /home/rteague/dev/clusters/aws-c2/reproducer/roles/test-1/tasks/included_file.yml:2
ok: [localhost] => {
    "msg": "included file"
}
META: ran handlers
META: ran handlers

PLAY RECAP ***********************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0   

This is a variation of the issue #26525 which was fixed in #26601.

@ansibot ansibot added affects_2.4 This issue/PR affects Ansible v2.4 bug_report needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jul 26, 2017
@abadger abadger added c:playbook/role_include c:playbook/task_include and removed needs_triage Needs a first human triage before being processed. labels Jul 27, 2017
@mckerrj mckerrj added the P2 Priority 2 - Issue Blocks Release label Aug 3, 2017
jimi-c added a commit to jimi-c/ansible that referenced this issue Aug 4, 2017
This exposed some additional errors in logic in IncludeFile, which
had to be fixed to deal with the fact that the role path (unlike paths
from includes) are always absolute paths.

Fixes ansible#27345
s-hertel pushed a commit to s-hertel/ansible that referenced this issue Aug 4, 2017
This exposed some additional errors in logic in IncludeFile, which
had to be fixed to deal with the fact that the role path (unlike paths
from includes) are always absolute paths.

Fixes ansible#27345
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 bug This issue/PR relates to a bug. c:playbook/role_include c:playbook/task_include P2 Priority 2 - Issue Blocks Release support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants