0
votes

im about to make an ansible playbook for automatic updating some librarys

The error msg i got :
"msg": "The task includes an option with an undefined variable. The error was: 'lib_wheel_path' is undefined\n\nThe error appears to be in '/home/user/Desktop/setup/roles/lib/tasks/main.yml': line 4, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Download lib\n ^ here\n"

my ansible/vars file contains the path to libs :

local_path: "~/Some_Libraries/"
lib_wheel_path: "{{ local_path }}lib/"

the ansible/role/lib/vars/main.yml file contains :

lib_path: "{{ lib_wheel_path }}"
lib_wheels: "'{{ lib_path }}' | regex_findall('(lib\\S*\\.whl)') | sort(reverse=True) }}"

the ansible/role/lib/tasks/main.yml file contains :

- name: Download lib
  copy:
    src: "{{ lib_path }}/{{ lib_wheels[0] }}"
    dest: /tmp
    remote_src: true

- name: Install lib
  pip:
    name: file:///tmp/{{ lib_wheels[0] }}
  become: yes

It's expected it will include the ansible/vars which contains the lib_wheel_path, i f im not wrong about how ansible works

1

1 Answers

0
votes

You have to include the var file. for eg: If your var file is ansible/role/lib/vars/lib.yml

local_path: "~/Some_Libraries/"
lib_wheel_path: "{{ local_path }}lib/"

In your playbook include it as below.

- name: vars
  include_vars: lib.yml

- name: Download lib
  copy:
    src: "{{ lib_path }}/{{ lib_wheels[0] }}"
    dest: /tmp
    remote_src: true

- name: Install lib
  pip:
    name: file:///tmp/{{ lib_wheels[0] }}
  become: yes