# Ansible configuration to run an Ansible Galaxy playbook

**URL:** <https://forum.ansible.com/t/ansible-configuration-to-run-an-ansible-galaxy-playbook/34543>\
**Category:** Ansible Project\
**Tags:** galaxy-ng, kubernetes\
**Created:** [January 29, 2021, 8:27pm UTC](https://forum.ansible.com/t/ansible-configuration-to-run-an-ansible-galaxy-playbook/34543 "2021-01-29T20:27:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeremy\_Tourville](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jeremy_tourville/32/8162_2.png) [@Jeremy\_Tourville](https://forum.ansible.com/u/Jeremy_Tourville)\
**Post date:** [January 29, 2021, 8:27pm UTC](https://forum.ansible.com/t/ansible-configuration-to-run-an-ansible-galaxy-playbook/34543/1 "2021-01-29T20:27:38Z")

</div>

Hello,

I have been learning to use Ansible through Red Hat training for approximately the last 6 months or so. I have learned how to build some of my own basic play books and roles.  
For the first time i have decided to download and run a role from Ansible Galaxy ([https://galaxy.ansible.com/geerlingguy/kubernetes](https://galaxy.ansible.com/geerlingguy/kubernetes)). I have several questions about making sure my environment, ansible.cfg, inventory, etc is set up properly.

My Environment-

Ansible Control Node:  
Ansible 2.9 on CentOS 8.2

Target Machines:  
CentOS 8.3  
Kubernetes Master: kube1  
Kubernetes Workers: kube2, kube3

ANSIBLE CONFIG  
/home/ansuser/ansible/ansible.cfg  
[defaults]  
inventory=./inventory  
remote\_user=ansuser  
ask\_pass=false

[privilege\_escalation]  
becom=true  
become\_method=sudo  
become\_ask\_pass=true

INVENTORY  
/home/ansuser/ansible/inventory  
[kube-master]  
[kube1.idm.nac-issa.org](http://kube1.idm.nac-issa.org) kubernetes\_role=master

[kube-node]  
[kube2.idm.nac-issa.org](http://kube2.idm.nac-issa.org) kubernetes\_role=node  
[kube3.idm.nac-issa.org](http://kube3.idm.nac-issa.org) kubernetes\_role=node

I have created a user “ansuser”. Ansuser has sudo permissions (but not passwordless sudo) and is a member of the wheel group. I created my ssh keys with that user and copied them to the target servers. ansible all -m ping works without any issues.

If I try to run the playbook with:  
$ansible-playbook kubernetes.yml  
I will quickly run into a failure, the error is: “This command has to be run under the root user”. When prompted for the BECOME password, I provided the ansuser password.

I can add become\_user=root to the config and provide the root user password. I still get the same error message.

I could change my remote\_user=root and that will allow the playbook to completely finish everything but that forces me to run my kubernetes cluster as root to download images, run pods, etc. That doesn’t seem right.

I could also adjust the specific play to use become, such as:

- name: Ensure the httpd service is running  
service:  
name: httpd  
state: started  
become: true

but that would be a lot of work because there are multiple sections requiring root privileges (further making me believe I am doing something wrong) and the developer who published these roles has a lot of experience.

What am I missing? It seems like something is not correct with my environment that causes the playbook to fail at multiple points where root privilege is needed. There must be some info I am not understanding or need explained in a different way so it makes sense. I welcome everyone’s input. Thanks!

----KUBERNETES.YML PLAYBOOK----

---

<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:** [January 29, 2021, 8:51pm UTC](https://forum.ansible.com/t/ansible-configuration-to-run-an-ansible-galaxy-playbook/34543/2 "2021-01-29T20:51:48Z")

</div>

> Hello,
> 
> I have been learning to use Ansible through Red Hat training for approximately the last 6 months or so. I have learned how to build some of my own basic play books and roles.  
> For the first time i have decided to download and run a role from Ansible Galaxy ([https://galaxy.ansible.com/geerlingguy/kubernetes](https://galaxy.ansible.com/geerlingguy/kubernetes)). I have several questions about making sure my environment, ansible.cfg, inventory, etc is set up properly.
> 
> My Environment-
> 
> Ansible Control Node:  
> Ansible 2.9 on CentOS 8.2
> 
> Target Machines:  
> CentOS 8.3  
> Kubernetes Master: kube1  
> Kubernetes Workers: kube2, kube3
> 
> ANSIBLE CONFIG  
> /home/ansuser/ansible/ansible.cfg  
> [defaults]  
> inventory=./inventory  
> remote\_user=ansuser  
> ask\_pass=false
> 
> [privilege\_escalation]  
> becom=true

Typo?

> become\_method=sudo  
> become\_ask\_pass=true
> 
> INVENTORY  
> /home/ansuser/ansible/inventory  
> [kube-master]  
> [kube1.idm.nac-issa.org](http://kube1.idm.nac-issa.org) kubernetes\_role=master
> 
> [kube-node]  
> [kube2.idm.nac-issa.org](http://kube2.idm.nac-issa.org) kubernetes\_role=node  
> [kube3.idm.nac-issa.org](http://kube3.idm.nac-issa.org) kubernetes\_role=node
> 
> I have created a user “ansuser”. Ansuser has sudo permissions (but not passwordless sudo) and is a member of the wheel group. I created my ssh keys with that user and copied them to the target servers. ansible all -m ping works without any issues.
> 
> If I try to run the playbook with:  
> $ansible-playbook kubernetes.yml  
> I will quickly run into a failure, the error is: “This command has to be run under the root user”. When prompted for the BECOME password, I provided the ansuser password.
> 
> I can add become\_user=root to the config and provide the root user password. I still get the same error message.
> 
> I could change my remote\_user=root and that will allow the playbook to completely finish everything but that forces me to run my kubernetes cluster as root to download images, run pods, etc. That doesn’t seem right.
> 
> I could also adjust the specific play to use become, such as:
> 
> - name: Ensure the httpd service is running  
> service:  
> name: httpd  
> state: started  
> become: true
> 
> but that would be a lot of work because there are multiple sections requiring root privileges (further making me believe I am doing something wrong) and the developer who published these roles has a lot of experience.
> 
> What am I missing? It seems like something is not correct with my environment that causes the playbook to fail at multiple points where root privilege is needed. There must be some info I am not understanding or need explained in a different way so it makes sense. I welcome everyone’s input. Thanks!
> 
> ## ----KUBERNETES.YML PLAYBOOK----
> 
> - hosts: all

Put ‘become: yes’ here and your entire playbook will use that.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Tourville](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jeremy_tourville/32/8162_2.png) [@Jeremy\_Tourville](https://forum.ansible.com/u/Jeremy_Tourville)\
**Post date:** [January 29, 2021, 10:08pm UTC](https://forum.ansible.com/t/ansible-configuration-to-run-an-ansible-galaxy-playbook/34543/3 "2021-01-29T22:08:28Z")

</div>

OMG, how did I miss that? no not a typo, that is what I had configured. Talk about missing something simple. Thanks for pointing out my mistake! 🙂
