2

I have a db host, on which some sql files are present. I want to source it into db using an ansible playbook. so I find all files & register in variable, then try to source those using below code.

- name: get schema files
  find:
    paths: "~/dbs/"
    recurse: no
    patterns: "*.sql"
  register: db_sql_files

- name: import schemas
  mysql_db:
    name: all
    state: import
    target: "{{ item['path'] }}"
    login_user: "{{ db_user }}"
    login_password: "{{ db_pass }}"
    with_items: "{{ db_sql_files['files'] }}"

when I run playbook, I get below error.

The task includes an option with an undefined variable. The error was: 'item' is undefined

1 Answer 1

1

It looks like the with_items entry has a wrong indentation. Removing two spaces from the with_items entry should fix the issue:

- name: import schemas
  mysql_db:
    name: all
    state: import
    target: "{{ item['path'] }}"
    login_user: "{{ db_user }}"
    login_password: "{{ db_pass }}"
  with_items: "{{ db_sql_files['files'] }}" # On the sime line as the mysql_db call. 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .