# Using Cpanel with Ansible

**URL:** <https://forum.ansible.com/t/using-cpanel-with-ansible/24894>\
**Category:** Ansible Project\
**Created:** [July 5, 2017, 5:12am UTC](https://forum.ansible.com/t/using-cpanel-with-ansible/24894 "2017-07-05T05:12:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fayad](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Fayad](https://forum.ansible.com/u/Fayad)\
**Post date:** [July 5, 2017, 5:12am UTC](https://forum.ansible.com/t/using-cpanel-with-ansible/24894/1 "2017-07-05T05:12:24Z")

</div>

Hi,

Let me explain our environment first:

We have about 500 cpanel servers which are either openvz VEs or physical servers. We are now using puppet to manage and carry out any common system administration tasks on the servers. Direct ssh root login is disabled on ll these servers.

Requirement: We need to setup ansible to replace puppet.

What I’ve done:

Since direct ssh root login is disabled, I’ve created a new user in the client server and set up key based authentication from ansible master server. Also gave sudo privileges to this user so that the user has got sufficient privileges to execute commands as the root user.

I tried a few ansible adhoc commands and they worked for a few times, for eg:

[ih\_ansible\_user@ansible /]$ ansible -m shell -a ‘/etc/init.d/exim status’ [test.cpanelserver.com](http://test.cpanelserver.com)  
[test.cpanelserver.com](http://test.cpanelserver.com) | SUCCESS | rc=0 \>\>  
exim (pid 28919 22473 21885 19961 19960 18016 16832 10399 10059 6131 3856 3657 3501 3431 2083 2012) is running…

[ih\_ansible\_user@ansible /]$ ansible -m shell -a ‘/etc/init.d/mysql status’ [test.cpanelserver.com](http://test.cpanelserver.com)  
[test.cpanelserver.com](http://test.cpanelserver.com) | SUCCESS | rc=0 \>\>  
SUCCESS! MySQL running (13701)

[ih\_ansible\_user@ansible /]$ ansible -m shell -a ‘df -h’ [test.cpanelserver.com](http://test.cpanelserver.com)  
[test.cpanelserver.com](http://test.cpanelserver.com) | SUCCESS | rc=0 \>\>  
Filesystem Size Used Avail Use% Mounted on  
/dev/simfs 2.0T 1.3T 598G 69% /

But after a few tries, I get the error:

[ih\_ansible\_user@ansible /]$ ansible -m shell -a ‘/etc/init.d/httpd status’ [test.cpanelserver.com](http://test.cpanelserver.com)  
test.cpanelserver.com| FAILED! =\> {  
“changed”: false,  
“failed”: true,  
“module\_stderr”: “Shared connection to [test.cpanelserver.com](http://test.cpanelserver.com) closed.\r\n”,  
“module\_stdout”: “sudo: PERM\_ROOT: setresuid(0, -1, -1): too many processes\r\n”,  
“msg”: “MODULE FAILURE”,  
“rc”: 1  
}

I’m also getting a similar error when I execute the command from the client server as the ansible user:

ih\_ansible\_user@test [/root]# sudo httpd status  
sudo: PERM\_ROOT: setresuid(0, -1, -1): too many processes

Upon searching, I could see that the number of processes for users other than root is restricted in cpanel servers. The suggested fix is to disable shell fork bomb protection but it is not secure. Also I’m unable to increase the limit.

Currently I’m stuck at this point. Please let me know if this is the correct approach, like adding a new user for ansible etc.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 6, 2017, 5:00pm UTC](https://forum.ansible.com/t/using-cpanel-with-ansible/24894/2 "2017-07-06T17:00:58Z")

</div>

Is it not possible to lift this restriction on the user that runs Ansible?

There work in progress to make Ansible use thread instead for forking, this might help your case.

[https://groups.google.com/forum/#!topic/ansible-devel/2-yqn3zuWg8](https://groups.google.com/forum/#!topic/ansible-devel/2-yqn3zuWg8)

---

<div class="post-metadata">

**Author:** ![Fayad](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Fayad](https://forum.ansible.com/u/Fayad)\
**Post date:** [July 6, 2017, 8:19pm UTC](https://forum.ansible.com/t/using-cpanel-with-ansible/24894/3 "2017-07-06T20:19:39Z")

</div>

I tried increasing the limits but it won’t take effect unless i disable shell fork bomb protection from WHM interface. And is not a good idea to disable it.

Fayad

---

<div class="post-metadata">

**Author:** ![Fayad](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Fayad](https://forum.ansible.com/u/Fayad)\
**Post date:** [July 17, 2017, 1:15pm UTC](https://forum.ansible.com/t/using-cpanel-with-ansible/24894/4 "2017-07-17T13:15:07Z")

</div>

The issue was fixed by creating the ansible user on the client server with uid less than 500 which are meant for system accounts and the limit is not applicable for these accounts.

Fayad

---

<div class="post-metadata">

**Author:** ![Fayad](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Fayad](https://forum.ansible.com/u/Fayad)\
**Post date:** [July 28, 2017, 3:50am UTC](https://forum.ansible.com/t/using-cpanel-with-ansible/24894/5 "2017-07-28T03:50:29Z")

</div>

Is it required to run ansible commands as the root user?

If running as another user, is there any privileges required to be given for this user?

Fayad

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 28, 2017, 1:31pm UTC](https://forum.ansible.com/t/using-cpanel-with-ansible/24894/6 "2017-07-28T13:31:44Z")

</div>

> Is it required to run ansible commands as the root user?

No.

> If running as another user, is there any privileges required to be given  
> for this user?

No.  
But if a command or a action need privileges the user doesn't have it will of course not work with Ansible either.

---

<div class="post-metadata">

**Author:** ![Fayad](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Fayad](https://forum.ansible.com/u/Fayad)\
**Post date:** [July 28, 2017, 3:12pm UTC](https://forum.ansible.com/t/using-cpanel-with-ansible/24894/7 "2017-07-28T15:12:05Z")

</div>

Thanks Kai.

I’ve added the following line in the /etc/sudoers file on the client server:

ansible\_user ALL=(root) NOPASSWD: ALL

Won’t this provide enough privilege for the ansible user to execute commands as root?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [July 28, 2017, 6:25pm UTC](https://forum.ansible.com/t/using-cpanel-with-ansible/24894/8 "2017-07-28T18:25:37Z")

</div>

Yes, it will, but you still has to tell ansible to use become, it won't magically use sudo unless you specify become: true or use the option -b on the command line.

---

<div class="post-metadata">

**Author:** ![Fayad](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Fayad](https://forum.ansible.com/u/Fayad)\
**Post date:** [August 4, 2017, 6:49am UTC](https://forum.ansible.com/t/using-cpanel-with-ansible/24894/9 "2017-08-04T06:49:37Z")

</div>

Hi,

Yes, I’ve already enabled it. Please see the below lines:

[privilege\_escalation]  
become=True  
become\_method=sudo  
become\_user=root  
become\_ask\_pass=False

---

<div class="post-metadata">

**Author:** ![Fayad](https://avatars.discourse-cdn.com/v4/letter/f/ea5d25/32.png) [@Fayad](https://forum.ansible.com/u/Fayad)\
**Post date:** [August 16, 2017, 3:21am UTC](https://forum.ansible.com/t/using-cpanel-with-ansible/24894/10 "2017-08-16T03:21:09Z")

</div>

Is this the correct method if root login is disabled?

Fayad
