Ansible – become_user and include_tasks modification since 2.5

Ansible – become_user and include_tasks modification since 2.5

21 October 2018 4 By Eric Deleforterie

There is a modification since Ansible 2.5 with the way that include_tasks works with become_user

Before Ansible 2.5, your code like this one works fine, you will have the Sylvie user id

---
- hosts: localhost
  gather_facts: no
  tasks:
    - name: test
      include_tasks: test_include_id.yml
      become: yes
      become_user: sylvie
---
- shell: id

Since Ansible 2.5 a change in Dynamic includes and attribute inheritance was implemented causing this previous playbook to show your user id instead of Sylvie user id.

Since Ansible 2.5 use this syntax with a block to have the become_user works

---
- hosts: localhost
  gather_facts: no
  tasks:
    - block:
      - name: test
        include_tasks: test_include_id.yml
      become: yes
      become_user: sylvie

 

 

Please follow and like us: