include_role with different user is not working

Ansible Version 2.5.4

I have a playbook which include two different role. Playbook run on localhost as root using ansible-pull

role1. rpm installation require root access.
role2. Application Configuration need to run as application user

Tries the role2 es-configure with become_user and ansible_user as below. Still the role execute as root

With become: yes

This give you the answers

https://docs.ansible.com/ansible/2.5/porting_guides/porting_guide_2.5.html#dynamic-includes-and-attribute-inheritance

In the link they use tags but this is also true for become since that's also an attribute.

As an extension of the link Kai provided, you can use block to help you achieve your goal:

  • block:
  • include_role:
    name: roles/elasticsearch/es-configure
    vars:
    version: “6.2.4”
    user: eseng
    group: eseng
    become: yes
    become_user: eseng