2

I am trying to run a playbook which execute against variables stored in the host_vars. This is the solution layout:

  • /host_vars/f5-test
  • /inventory/hosts
  • /playbook.yml

The content of the files are as follows:

/inventory/host:

[f5-test]
localhost

/host_vars/hosts

f5_user:user
f5_password:password
f5_server:server

/playbook.yml

- name: Playbook
  hosts: f5-test
  gather_facts: no
  gather_subset: no

  tasks:
    - name: Taks_01
      tags: "bigip-node"
      bigip_node:
        server: "{{f5_server}}"
        user: "{{f5_user}}"
        password: "{{f5_password}}"
        state: "present"
        partition: "Common"
        host: "10.20.30.40"
        name: "F5_Node"
        session_state: "enabled"
        description: "description"
      delegate_to: localhost

However when we execute the following command:

sudo ansible-playbook playbook.yml -i inventory/hosts -vvvv

I get the following error:

task path: /home/dev/ansible/playbook.yml:9
fatal: [localhost]: FAILED! => {
    "failed": true,
    "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'f5_server' is undefined\n\nThe error appears to have been in '/home/dev/ansible/playbook.yml': line 9, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  tasks:\n    - name: Task_01\n      ^ here\n"
}

Any idea why it is not being picked up? I set up my project in the same structure found in the F5 ansible example, which can be found here.

Thanks!

jonatzin
  • 922
  • 1
  • 13
  • 30
  • Please read your question and fix obvious inconsistencies. It's hard to tell which mistakes you did when writing the question and which when setting up the files. – techraf Jul 18 '17 at 13:48

3 Answers3

6

In your example hosts file f5-test is a group, not a host.

So put your variables into a group_vars file: ./group_vars/f5-test.yml:

f5_user: user
f5_password: password
f5_server: server
Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193
0

The host_vars directory needs to be in the same folder as your inventory. So move /host_vars/f5-test to /inventory/host_vars/f5-test. Take a look at the best practices page for more info.

kfreezy
  • 1,499
  • 12
  • 16
  • I moved the folder as you suggested however the issue persists. Also by this logic the f5 example would not work, which it does. https://github.com/F5Networks/f5-ansible/tree/devel/examples/000-getting-started – jonatzin Jul 18 '17 at 13:23
  • 1
    You'll also need to change the filename from `f5-test` to `localhost` since "f5-test" is your group name. You could alternatively add a `group_vars` directory and move `f5-test` there if you want. – kfreezy Jul 18 '17 at 13:42
0

#

In your example hosts file f5-test is a group

/inventory/host:

[f5-test] ---this is considered as a group

localhost --- this is considered as a host

so now create a host_vars/localhost

Then it will work