# Switch to root user using dzdo

**URL:** <https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173>\
**Category:** Ansible Project\
**Created:** [February 7, 2020, 10:45am UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173 "2020-02-07T10:45:02Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy\_Njock](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@Jeremy\_Njock](https://forum.ansible.com/u/Jeremy_Njock)\
**Post date:** [February 7, 2020, 10:45am UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/1 "2020-02-07T10:45:02Z")

</div>

I have an ansible playblook running some tasks for my user, which I log in through ssh.

The user has root privileges by running following command in the terminal:

`dzdo su -`

It’s actually the only way (no sudo, no root password) to get root access.

Now, what I want to do is to switch my user to root at a certain point in my ansible-playbook, using this **dzdo su -** behavior.

How to do this?

---

<div class="post-metadata">

**Author:** ![Work\_Email](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@Work\_Email](https://forum.ansible.com/u/Work_Email)\
**Post date:** [February 7, 2020, 8:17pm UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/2 "2020-02-07T20:17:22Z")

</div>

as a workaround, you can change the file permission on linux to act as root for your target area.

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [February 7, 2020, 8:48pm UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/3 "2020-02-07T20:48:05Z")

</div>

That sounds like throwing all security out of the window.  
Please refrain from giving this kind of useless advice...

---

<div class="post-metadata">

**Author:** ![cassell](https://avatars.discourse-cdn.com/v4/letter/c/ecae2f/32.png) [@cassell](https://forum.ansible.com/u/cassell)\
**Post date:** [February 7, 2020, 9:35pm UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/4 "2020-02-07T21:35:01Z")

</div>

Use become\_method=dzdo

If they literally require you to type "dzdo su -", then you should talk to your security folks to get a saner policy. (There's likely hacks that can be done, but "hacks")

V/r,  
James Cassell

---

<div class="post-metadata">

**Author:** ![Work\_Email](https://avatars.discourse-cdn.com/v4/letter/w/34f0e0/32.png) [@Work\_Email](https://forum.ansible.com/u/Work_Email)\
**Post date:** [February 7, 2020, 11:05pm UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/5 "2020-02-07T23:05:03Z")

</div>

oh yea? how’s that? Please do explain!

---

<div class="post-metadata">

**Author:** ![Jeremy\_Njock](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@Jeremy\_Njock](https://forum.ansible.com/u/Jeremy_Njock)\
**Post date:** [February 9, 2020, 4:21pm UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/6 "2020-02-09T16:21:14Z")

</div>

It’s the only way and there won’t be a change in the process soon, so I need to deal with it.  
They provide me a VM with a login, where I only can have root access to login with the command **dzdo su -** for 1 week to prepare the VM for real usage.  
I use this temporary dzdo root access to install sudo for further usage.  
To automate this process I need to write an ansible playbook.

And I tried to use **become\_method=dzdo** but this fails during the run of the playbook.  
I think because I still need to specify the **su -** part of it.

Thanks

---

<div class="post-metadata">

**Author:** ![Vishal\_Bobade](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Vishal\_Bobade](https://forum.ansible.com/u/Vishal_Bobade)\
**Post date:** [February 9, 2020, 4:34pm UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/7 "2020-02-09T16:34:05Z")

</div>

Hi,

Could you try this, before you want the task done with dzdo previleges.

become: yes  
become\_method: dzdo

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 9, 2020, 7:13pm UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/8 "2020-02-09T19:13:07Z")

</div>

> It's the only way and there won't be a change in the process soon, so I need to deal with it.  
> They provide me a VM with a login, where I only can have root access to login with the command \*dzdo su -\* for 1 week to  
> prepare the VM for real usage.  
> I use this temporary dzdo root access to install sudo for further usage.  
> To automate this process I need to write an ansible playbook.  
> And I tried to use \*become\_method=dzdo \*but this fails during the run of the playbook.  
> I think because I still need to specify the \*su - \*part of it.

You can try

&nbsp;&nbsp;&nbsp;&nbsp;become\_flags: 'su -'

And please post the error message if it still fails.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![Jeremy\_Njock](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@Jeremy\_Njock](https://forum.ansible.com/u/Jeremy_Njock)\
**Post date:** [February 10, 2020, 4:40pm UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/9 "2020-02-10T16:40:20Z")

</div>

I followed your suggestions, thanks for that.

I have now following task:

`

- name: Install needed packages for Docker  
yum:  
name: yum-utils,device-mapper-persistent-data,lvm2  
state: latest  
become: yes  
become\_method: dzdo  
become\_flags: ‘su -’  
`

When I run my playbook, it fails with following error message.

fatal: [10.7.201.114]: FAILED! =\> {“changed”: false, “module\_stderr”: “”, “module\_stdout”: “”, “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”, “rc”: 1}

---

<div class="post-metadata">

**Author:** ![Vishal\_Bobade](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Vishal\_Bobade](https://forum.ansible.com/u/Vishal_Bobade)\
**Post date:** [February 10, 2020, 5:44pm UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/10 "2020-02-10T17:44:05Z")

</div>

Hi,

Does it requires become\_flags? Could you try commenting out that one.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Njock](https://avatars.discourse-cdn.com/v4/letter/j/e9a140/32.png) [@Jeremy\_Njock](https://forum.ansible.com/u/Jeremy_Njock)\
**Post date:** [February 10, 2020, 6:46pm UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/11 "2020-02-10T18:46:00Z")

</div>

As requested I commented out the **become\_flags** , which gives me the following task:

`

- name: Install needed packages for Docker  
yum:  
name: yum-utils,device-mapper-persistent-data,lvm2  
state: latest  
become: yes  
become\_method: dzdo  
`

And this gives as result the same error

fatal: [10.7.201.114]: FAILED! =\> {“changed”: false, “module\_stderr”: “”, “module\_stdout”: “”, “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”, “rc”: 1}

---

<div class="post-metadata">

**Author:** ![Vishal\_Bobade](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Vishal\_Bobade](https://forum.ansible.com/u/Vishal_Bobade)\
**Post date:** [February 11, 2020, 7:25am UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/12 "2020-02-11T07:25:30Z")

</div>

Hi,

Seems related to the particular module you are trying to use here.

Could you try performing this manually by ansible i.e. not by using playbook with debug mode enabled and see what error u see.

---

<div class="post-metadata">

**Author:** ![Vishal\_Bobade](https://avatars.discourse-cdn.com/v4/letter/v/c57346/32.png) [@Vishal\_Bobade](https://forum.ansible.com/u/Vishal_Bobade)\
**Post date:** [February 11, 2020, 7:27am UTC](https://forum.ansible.com/t/switch-to-root-user-using-dzdo/32173/13 "2020-02-11T07:27:52Z")

</div>

I would assume that you could run with `-vvv` and it will show you the stdout/stderr that indicates the failure in execution.
