Gustavo Silva Costa
Gustavo Silva Costa

Reputation: 53

Ansible failed undefined variable

I trying use simple ansible and receive the following error message

fatal: [localhost]: FAILED! => { "msg": "The task includes an option with an undefined variable. The error was: 'entregas' is undefined\n\nThe error appears to be in '/home/gustavo/Documents/ansible/roles/build/tasks/main.yml': line 2, 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 : Clone and pull\n ^ here\n" }

My directory

.
├── build.yml
├── roles
    ├── build
        ├── defaults
            ├── main.yml
        ├── tasks
            ├── main.yml

And my files

build.yml

---
- name: Pull Git
  hosts: localhost
  connection: local 
  roles: 
  - build

Default -> main.yml

---
dest_path : /tmp/ansible/test
sh_key_path : /root/.ssh/id_rsa
entregas-web : **bit bucket ssh**

tasks -> main.yml

---
- name : Clone and pull
  become : true
  ansible.builtin.git :
    repo : "{{ entregas-web }}"
    key_file : "{{ ssh_key_path }}"
    dest : "{{ dest_path }}"
    refspec : '+refs/pull/* :refs/heads/*'
    force : yes
    version : master

that happen when i throw this command

ansible-playbook build.yml -u root -vvvvv

or

ansible-playbook build.yml -vvvv

Upvotes: 1

Views: 1466

Answers (1)

dgw
dgw

Reputation: 13666

The variable name is invalid. Valid variable names do not contain a - (dash).

This is why your error message mentions a missing variable entregas.

See the documentation on variable names.

Upvotes: 4

Related Questions