Confused newbie - ERROR! the field 'hosts' is required but was not set

1,987 views
Skip to first unread message

GM

unread,
Aug 15, 2019, 9:23:05 PM8/15/19
to Ansible Project
Hi there - first I will post my response from when I run my playbook:

ansible-playbook -vv glen.yml

ansible-playbook 2.5.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/gmillard/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 2.7.15 (default, May  9 2018, 11:32:33) [GCC 7.3.1 20180130 (Red Hat 7.3.1-2)]
Using /etc/ansible/ansible.cfg as config file

PLAYBOOK: glen.yml *******************************************************************************************************************************************************************************************
2 plays in glen.yml

PLAY [all] ***************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************************************************************
task path: /home/gmillard/myplatform/OtherStuff/glen.yml:2
ok: [fedoracontrol]
META: ran handlers
META: ran handlers
META: ran handlers
ERROR! the field 'hosts' is required but was not set

Now, I'll post the playbook itself:
---
- hosts: all
- name: "download artifactory"
  tasks:
  - get_url:
      headers:  "X-JFrog-Art-Api:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
      dest: $PWD
      mode: 0644

Two things:
1. Why am I getting the ERROR! the field 'hosts' is required but was not set -  I'm thinking that my formatting/indentations are incorrect.
2. I'm attempting to grab an artifact from JFrog Artifactory - using the get_url module - am I using it correctly?  

Any and all help is appreciated. Thanks in advance.

G


Zolvaring

unread,
Aug 15, 2019, 9:43:15 PM8/15/19
to Ansible Project
The problem in this case is just the yaml syntax. "-" denotes the start of a new item, typically in a list, so when you write:

- hosts
- name

You are actually writing two separate objects, when what you want is:

- name: "download artifactory"
  hosts: all

Zolvaring

unread,
Aug 15, 2019, 9:46:46 PM8/15/19
to Ansible Project
In regards to your second question (sorry I missed it), the module looks okay except you need to indent the module out one more indentation space:
- name:
  hosts:
  tasks:
    - get_url:
        url:

The only other thing that looks immediately wrong to me is your destination parameter -- I don't think "$PWD" will work in this case ansible won't resolve the command as you execute it. If you are trying to put it in the current working directory of the ansible executor you can try "./" or specify the directory with set_fact or a variable.
      

On Thursday, August 15, 2019 at 6:23:05 PM UTC-7, GM wrote:

GM

unread,
Aug 16, 2019, 7:33:44 AM8/16/19
to Ansible Project
Thanks much my friend - that fixed things - for now. It's got some other weirdness going on but I think it's an infrastructure issue.

Glen
Reply all
Reply to author
Forward
0 new messages