semaphore icon indicating copy to clipboard operation
semaphore copied to clipboard

become sudo does not works

Open bahamut657 opened this issue 3 years ago • 3 comments

- name: Example
  hosts: rpi-server
  become: yes
  become_method: sudo
  gather_facts: false
  tasks:
    - name: "Update APT repositories  and cache"
      apt:
        update_cache: yes
        force_apt_get: yes
        cache_valid_time: 3600

Seems to run the update without becoming root (using sudo) Inventory configuration already set the "sudo credentials"

How to make it works? I'm trying to update an RPI where sudo su (with user pi), get root with no password

Regards and well done for the nice work

bahamut657 avatar May 30 '22 10:05 bahamut657

I have a similar problem, "become: yes" does not work below is my configuration

 # Hosts: where our play will run and options it will run with
  hosts: lab
  become: yes

  tasks:
    - name: User test 1
      become: yes
      command: id -un
      register: login
    - debug: msg="Logged in as user {{ login.stdout }}"

    - name: user test 2
      command: sudo id -un
      register: login
    - debug: msg="Logged in as user {{ login.stdout }}"

result:

TASK [debug] *******************************************************************
ok: [lab1] => {
"msg": "Logged in as user ubuntu"
}
TASK [user test 2] *************************************************************
changed: [lab1]
TASK [debug] *******************************************************************
ok: [lab1] => {
"msg": "Logged in as user root"
}

Inventory:

[lab]
lab1 ansible_ssh_host=192.168.100.1 ansible_port=22 ansible_ssh_user=ubuntu

[lab:vars]
ansible_connection=ssh
ansible_user=ubuntu
ansible_ssh_password=1
ansible_port=22
ansible_become_password=1

odmin4eg avatar May 31 '22 03:05 odmin4eg

I have the exact same issue as described above. The role I'm trying to deploy works just fine on another Ansible install, but not in semaphore.

AngelFreak avatar Jun 24 '22 09:06 AngelFreak

I faced the same problem.

The work around for me was to clean the "Sudo Credentials" form from the related inventory, then i added ansible_become_password="{{ sudo_password_defined_in_a_vaulted_var }}" to the host vars in said inventory.

Hope this bug will be solved soon enough !

RphCos avatar Jul 18 '22 21:07 RphCos

I faced the same problem! @RphCos: Thanks for sharing your solution - it worked for me.

helmut8960 avatar Dec 05 '22 08:12 helmut8960

same issue here....

alexsalex avatar Jan 06 '23 10:01 alexsalex