Klevin Kona
Klevin Kona

Reputation: 361

ansible Task separation via Variables must be stored as a dictionary/hash

- name: gather os specific variables
  include_vars: "{{ item }}"
  with_first_found:
    - "{{ ansible_distribution }}-{{ ansible_distribution_major_version}}.yml"
    - "{{ ansible_distribution }}.yml"
  tags: vars

Trying to setup a multi linux distros ansible playbook i did used the suggested playbook from the official ansible doc https://ansible-tips-and-tricks.readthedocs.io/en/latest/os-dependent-tasks/variables/

i did added Centos-6.yml and Debian-9.yml for tests but the result is the following

failed: [1.1.1.1] (item=/home/ansible/ansible-scripts/2AllInOne/CentOS-6.yml) => { "ansible_facts": {}, "ansible_included_var_files": [], "ansible_loop_var": "item", "changed": false, "item": "/home/ansible/ansible-scripts/2AllInOne/CentOS-6.yml", "message": "/home/ansible/ansible-scripts/2AllInOne/CentOS-6.yml must be stored as a dictionary/hash"

Any suggestion what the issue can be?

Upvotes: 2

Views: 7877

Answers (2)

Anand Subburaman
Anand Subburaman

Reputation: 1

Resolved the issue after modifying the yml as below:

1 ---  
2 - User_pass: varfileinclude

to

1 ---

2 User_pass: varfileinclude

# removed "-" from the variable. 

Upvotes: 0

Vladimir Botka
Vladimir Botka

Reputation: 68144

Q: CentOS-6.yml must be stored as a dictionary/hash. What the issue can be?

A: The issue is the format of the file CentOS-6.yml. It must be a valid YAML and must contain dictionary/hash aka mapping. For example

shell> cat CentOS-6.yml
my_dictionary:
  my_distro: Centos
  my_major: 6
  my_file: CentOS-6.yml

Upvotes: 1

Related Questions