# ERROR! the field 'hosts' is required but was not set

**URL:** <https://forum.ansible.com/t/error-the-field-hosts-is-required-but-was-not-set/32311>\
**Category:** Ansible Developer\
**Created:** [February 23, 2020, 4:09pm UTC](https://forum.ansible.com/t/error-the-field-hosts-is-required-but-was-not-set/32311 "2020-02-23T16:09:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daley\_Okuwa1](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Daley\_Okuwa1](https://forum.ansible.com/u/Daley_Okuwa1)\
**Post date:** [February 23, 2020, 4:09pm UTC](https://forum.ansible.com/t/error-the-field-hosts-is-required-but-was-not-set/32311/1 "2020-02-23T16:09:12Z")

</div>

I have written a simple script to patch my red hat server and it is comming out with this error message when i run : ansible-playbook linuxpatch.yml

ERROR! the field ‘hosts’ is required but was not set

in /etc/ansible/hosts i only have an entry of testserver

---

<div class="post-metadata">

**Author:** ![James\_Tanner](https://avatars.discourse-cdn.com/v4/letter/j/53a042/32.png) [@James\_Tanner](https://forum.ansible.com/u/James_Tanner)\
**Post date:** [February 23, 2020, 6:37pm UTC](https://forum.ansible.com/t/error-the-field-hosts-is-required-but-was-not-set/32311/2 "2020-02-23T18:37:02Z")

</div>

The preceding hyphen in front of “become\_user” is initiating a new play segment. Remove that hyphen so that become user becomes a key of the play that was started by your “- hosts” declaration.

---

<div class="post-metadata">

**Author:** ![Daley\_Okuwa1](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Daley\_Okuwa1](https://forum.ansible.com/u/Daley_Okuwa1)\
**Post date:** [February 24, 2020, 7:00pm UTC](https://forum.ansible.com/t/error-the-field-hosts-is-required-but-was-not-set/32311/3 "2020-02-24T19:00:33Z")

</div>

James,

Thanks  
That worked but also another error popped up below  
I think maybe because it is redhat 7.2

ansible-playbook linuxpatch.yml

PLAY [testserver] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Gathering Facts] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
ok: [testserver]

TASK [update the system] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [testserver]: FAILED! =\> {“changed”: false, “msg”: “There are no enabled repos.\n Run "yum repolist all" to see the repos you have.\n You can enable repos with yum-config-manager --enable \n”, “rc”: 1, “results”: }

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
testserver : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

---

<div class="post-metadata">

**Author:** ![ansiblekrazy](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@ansiblekrazy](https://forum.ansible.com/u/ansiblekrazy)\
**Post date:** [February 25, 2020, 8:40am UTC](https://forum.ansible.com/t/error-the-field-hosts-is-required-but-was-not-set/32311/4 "2020-02-25T08:40:07Z")

</div>

> > fatal: [testserver]: FAILED! =\> {“changed”: false, “msg”: “There are no enabled repos.\n Run "yum repolist all" to see the repos you have.\n You can enable repos with yum-config-manager --enable \n”, “rc”: 1, “results”: }

Looks like it is related to repo. Do you mind to check if the repo is available on your system

---

<div class="post-metadata">

**Author:** ![Daley\_Okuwa1](https://avatars.discourse-cdn.com/v4/letter/d/958977/32.png) [@Daley\_Okuwa1](https://forum.ansible.com/u/Daley_Okuwa1)\
**Post date:** [February 28, 2020, 1:01pm UTC](https://forum.ansible.com/t/error-the-field-hosts-is-required-but-was-not-set/32311/5 "2020-02-28T13:01:42Z")

</div>

Ok, I will check.
