user4889345
user4889345

Reputation:

Ansible - Unable to get variables to work

I am testing the variable feature in ansible along with include_vars and with_first_found.

My playbook is

---
- name: Load Variables from files.
  include_vars: "{{ item }}"
  with_first_found:
    - "a.yml"
    - "b.yml"
    - "default.yml"

- name: another play
  hosts: all
  tasks:
    - debug: msg="hello {{ http_port }}"

But when Im running this, I get the ERROR,

# ansible-playbook -i inventory/plat-inventory test.yaml 
ERROR! 'with_first_found' is not a valid attribute for a Play

The error appears to have been in '/root/config-3.0.98/ansible/test.yaml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- name: Load Variables from files.
  ^ here

default.yml states :

http_port: 80

What am I missing here ?

Upvotes: 0

Views: 504

Answers (1)

user140547
user140547

Reputation: 8200

As far as I know, include_vars should be a task, as the examples in its documentation

something like

- name: playbook
  hosts: somehosts
  gather_facts: false
  tasks:
    - name: "add some vars"
      include_vars: somefile.yml

But then, those variables won't probably be available in the other playbook.

Upvotes: 1

Related Questions