Problem change user with become or become_user

Hey,

Hello every body !!

I work on Ansible and i have problem, when i want use become: yes or become_user: root it’s not works.

My task is :

  • name: “Create directory”
    file:
    path: /var/apps
    state: directory
    become_user: root

But when i use this task just before :

  • set_fact:
    ansible_user: root

My directory is create with success !! WHY ?

Someone have any idea please community ansible ??? I’m desperte :frowning:

Thank you very much !!

Regards,

Karther

Hi Karther,

I’m not an expert in ansible but with my current experience I believe this works for you because you are logging in as root which is the owner of /var/ folder. ansible_user is a default variable.

Typically for other modules like lineinfile I add ansible_beome: yes, which means run the file as sudo. my ansible_beocme_password is defined as a variable so I guess you can try doing that.

Hey,

Hello every body !!

I work on Ansible and i have problem, when i want use become: yes or become_user: root it's not works.

My task is :

- name: "Create directory"
  file:
    path: /var/apps
    state: directory
  become_user: root

become_user only tells ansible what user to become - not that it use
privilege escalation.
Also, become_user is default 'root', so that directive is redundant.

Instead simply use:

become: yes

But when i use this task just before :

- set_fact:
      ansible_user: root

My directory is create with success !! WHY ?

This means that ansible will sign in to the server as root, so then no
permission issues.

If your system allows you to go straight in as root, you could possibly use “remote_user” before running the task (see below):

Hey,

Thanks very much community Ansible !!

The solution is to use remote_user: root for that ansible execut this task in root !!!

thank you very much guy !!! :slight_smile:

Regards,

Karther