Re: [ansible-project] Re: become: true does not work but -b works

2024-05-14 Thread Sameer Modak
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.

On Tuesday, May 14, 2024 at 8:12:07 PM UTC+5:30 Brian Coca wrote:

> 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.
>
> -- 
> --
> Brian Coca (he/him/yo)
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/fe433d00-869f-4e9d-b368-34680a8ff041n%40googlegroups.com.


Re: [ansible-project] Re: become: true does not work but -b works

2024-05-14 Thread Brian Coca
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.

-- 
--
Brian Coca (he/him/yo)

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACVha7czSxRiwqw6k5MgDEqZikk8%3DtLs5F-6uBsnZw%2B9RnG5Rg%40mail.gmail.com.


[ansible-project] Re: become: true does not work but -b works

2024-05-14 Thread Sameer Modak
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
On Tuesday, May 14, 2024 at 2:08:14 PM UTC+5:30 Sameer Modak wrote:

> 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
>
> ==
>
> Working fine,
>
> ansible-playbook prometheusjmxrole.yml -i ../inventory/staging.yaml -b 
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/49482827-c301-4366-92af-50a02f68c761n%40googlegroups.com.