skip to Main Content
- 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?

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. Resolved the issue after modifying the yml as below:

    1 ---  
    2 - User_pass: varfileinclude
    

    to

    1 ---
    
    2 User_pass: varfileinclude
    
    # removed "-" from the variable. 
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search