Why didn't Ansible see the attribute in the variable?

I have Ansible role "db" with a simple task:

- name: Check repos apt_repository: repo="{{ item.repo }}" state={{ item.state }} with_items: - "{{ apt_repos }}" 

In / defaults / mail.yml:

apt_repos:

  # Percona - { state: present, repo: 'deb http://repo.percona.com/apt wheezy main', keyserver: 'keyserver.ubuntu.com', key: '1C4CBDCDCD2EFD2A', needkey: True } - { state: present, repo: 'deb-src http://repo.percona.com/apt wheezy main', needkey: False } 

When I try to run this boot book:

 --- - hosts: test roles: - db 

I see an error:

 fatal: [10.10.10.10] => One or more undefined variables: 'unicode object' has no attribute 'repo' FATAL: all hosts have already failed -- aborting 

But I have another role with the same task and variable, and it works great. What's wrong?

+5
source share
1 answer

You want to do this:

 with_items: apt_repos 

apt_repos is a list. Sending it as - "{{ apt_repos }}" , optional - turns it into a list of lists. You also don't need quotes or braces in this case - they are pretty much just redundant in this type of situation.

+6
source

Source: https://habr.com/ru/post/1234369/


All Articles