# become: true does not work but -b works

**URL:** <https://forum.ansible.com/t/become-true-does-not-work-but-b-works/38781>\
**Category:** Ansible Project\
**Created:** [May 14, 2024, 8:38am UTC](https://forum.ansible.com/t/become-true-does-not-work-but-b-works/38781 "2024-05-14T08:38:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [May 14, 2024, 8:38am UTC](https://forum.ansible.com/t/become-true-does-not-work-but-b-works/38781/1 "2024-05-14T08:38:14Z")

</div>

Hello team,

I am running a role like below despite putting become true for install task i get error. However if run with -b it works.

Getting error while running this ,

ansible-playbook prometheusjmxrole.yml -i …/inventory/staging.yaml

The full traceback is:

WARNING: The below traceback may _not_ be related to the actual failure.

File “/tmp/ansible\_file\_payload\_CA4MQM/ansible\_file\_payload.zip/ansible/module\_utils/basic.py”, line 841, in set\_owner\_if\_different

os.lchown(b\_path, uid, -1)

failed: [10.xx.xx.xxx] (item=/etc/jmx\_prometheus/) =\> {

“ansible\_loop\_var”: “item”,

“changed”: false,

“gid”: 0,

“group”: “root”,

“invocation”: {

“module\_args”: {

“\_diff\_peek”: null,

“\_original\_basename”: null,

“access\_time”: null,

“access\_time\_format”: “%Y%m%d%H%M.%S”,

“attributes”: null,

“follow”: true,

“force”: false,

“group”: “confluent”,

“mode”: 493,

“modification\_time”: null,

“modification\_time\_format”: “%Y%m%d%H%M.%S”,

“owner”: “cp-kafka”,

“path”: “/etc/jmx\_prometheus/”,

“recurse”: false,

“selevel”: null,

“serole”: null,

“setype”: null,

“seuser”: null,

“src”: null,

“state”: “directory”,

“unsafe\_writes”: false

}

},

“item”: “/etc/jmx\_prometheus/”,

“mode”: “0755”,

“msg”: “chown failed: [Errno 1] Operation not permitted: ‘/etc/jmx\_prometheus/’”,

“owner”: “root”,

“path”: “/etc/jmx\_prometheus/”,

“secontext”: “unconfined\_u:object\_r:etc\_t:s0”,

“size”: 4096,

“state”: “directory”,

“uid”: 0

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [May 14, 2024, 8:43am UTC](https://forum.ansible.com/t/become-true-does-not-work-but-b-works/38781/2 "2024-05-14T08:43:53Z")

</div>

Task which throwing error:

name: Create Prometheus install and config directory

become: true. \<------ does not work

file:

path: “{{ item }}”

state: directory

mode: 0755

owner: “{{user}}”

group: “{{group}}”

loop:

- “{{ jmxexporter\_jar\_path | dirname }}”

- “{{ jmxexporter\_config\_path }}”

If i put become: true at role playbook it works but i dont want to give blanket become: true hence i was trying to do at task level.

vim prometheusjmxrole.yml

name: Deploy jmx\_exporter

hosts: all

become: true. \<---------------- works fine if we set it here but i dont want it in this way.

tasks:

- name: Importing jmx prometheus role

import\_role:

name: prometheusjmx

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 14, 2024, 2:41pm UTC](https://forum.ansible.com/t/become-true-does-not-work-but-b-works/38781/3 "2024-05-14T14:41:31Z")

</div>

We have tests for this and i just tested manually, become: true on a  
task does work. Tried with your task (supplying my own values for the  
vars) and it works the same, putting it on the task, the play, a  
block, role or command line. The only way i get it to 'not work' is  
setting ansible\_become: false , but that makes them ALL not work, not  
just the task level become.

I cannot tell from the email as it breaks formatting, but my guess  
would be that it is set to the task.

---

<div class="post-metadata">

**Author:** ![Sameer\_Modak](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sameer_modak/32/5180_2.png) [@Sameer\_Modak](https://forum.ansible.com/u/Sameer_Modak)\
**Post date:** [May 14, 2024, 3:05pm UTC](https://forum.ansible.com/t/become-true-does-not-work-but-b-works/38781/4 "2024-05-14T15:05:14Z")

</div>

Hello Brian,

Yes it works , Issue was my role was picking the values from roles directory instead from current directory hence despite making changes at current file become was not working.
