Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

include_tasks does not work with become after upgrade to ansible 2.8

Tags:

ansible

I've started getting

ERROR! 'become_user' is not a valid attribute for a TaskInclude

while using my playbooks with ansible 2.8.

It works fine with ansible 2.7 and earlier.

Error message says that the problem is in this file on the 'become_user' line:

- name: Install API software
  become: true
  become_user: "{{ namespace }}"
  include_tasks: utils/install_service.yml
  vars:
    service_name: api
    nodejs_service: true

I have not found anything obviously related to this in ansible docs or changelog.

like image 707
Aquajet Avatar asked Jun 12 '19 09:06

Aquajet


2 Answers

Found a solution in some old issue.

It seems like using 'become' with 'include_tasks' was an undocumented feature that was removed accidentally.

It can be solved by packing include_tasks into a block:

- block:
    - name: Install API software
      include_tasks: utils/install_service.yml
      vars:
        service_name: api
        nodejs_service: true

  become: true
  become_user: "{{ namespace }}"
like image 100
Aquajet Avatar answered Sep 28 '22 10:09

Aquajet


You should be able to simply add these to the variables list that you pass in (with the ansible_ prefix). So that would be:

- name: Install API software
  include_tasks: utils/install_service.yml
  vars:
    service_name: api
    nodejs_service: true
    ansible_become: true
    ansible_become_user: "{{ namespace }}"

For reference, see the upstream issue comment.

like image 30
colan Avatar answered Sep 28 '22 09:09

colan