Bootstrap FreeKB - Ansible - Resolve "must be privileged to use -u"
Ansible - Resolve "must be privileged to use -u"

Updated:   |  Ansible articles

Let's say something like this is being returned.

TASK [edit john.doe crontab] 
fatal: [server1]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"}, "changed": false, "msg": "must be privileged to use -u\n"}

 

I got this when attempting to update a users crontab using ansible.builtin.cron as a user a different user. In this example, the SSH connection is made to the target server as jane.doe and then an attempt is made to edit john.doe crontab.

- hosts: all
  gather_facts: False
  remote_user: jane.doe
  tasks:
  - name: edit john.doe crontab
    ansible.builtin.cron:
      user: john.doe
      name: 'my job'
      job: /usr/local/scripts/example.py
      special_time: hourly
      disabled: true
...

 

I was able to resolve this by including become_method: sudo. Check out my article FreeKB - Ansible - Understanding Become Privilege Escalation for more details on "become".

- hosts: all
  gather_facts: False
  remote_user: jane.doe
  become: yes
  become_method: sudo
  tasks:
  - name: edit john.doe crontab
    ansible.builtin.cron:
      user: john.doe
      name: 'my job'
      job: /usr/local/scripts/example.py
      special_time: hourly
      disabled: true
...

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter f9307b in the box below so that we can be sure you are a human.