Эта команда не выполняется
ansible-playbook -i inventory/hosts playbooks/example_play.yml
Вот файл инвентаризации / хостов
[localhost]
127.0.0.1 ansible_connection=local
Вот playbooks / example_play.yml
---
- name: variable precedence test
hosts: localhost
vars_files:
- "vars/{{ env }}.yml"
- "vars/{{ function }}.yml"
tasks:
- debug: var=server_memory_size
Несколько файлов groups_vars
// group_vars/dev
---
env: dev
// group_vars/stage
---
env: stage
// group_vars/web
---
function: web
Вот файлы vars. Все они имеют одну и ту же переменную, только разные значения (4 ГБ, 512 МБ и т. Д. c).
// vars/database.yml
---
server_memory_size: 2gb
Это моя структура каталогов
.
├── ansible.cfg
├── inventory
│ └── hosts
└── playbooks
├── example_play.yml
├── groups_vars
│ ├── database
│ ├── dev
│ ├── prod
│ ├── stage
│ └── web
├── roles
│ └── server
│ ├── defaults
│ │ └── main
│ │ ├── first.yml
│ │ └── second.yml
│ ├── files
│ │ └── test.sh
│ ├── handlers
│ │ └── main.yml
│ ├── meta
│ │ └── main.yml
│ ├── tasks
│ │ ├── install.yml
│ │ └── main.yml
│ ├── templates
│ │ └── hello.j2
│ └── vars
│ └── main.yml
└── vars
├── database.yml
├── dev.yml
├── prod.yml
├── stage.yml
└── web.yml
Ошибка была
/tmp/exercises/ansible# ansible-playbook -i inventory/hosts playbooks/example_play.yml
PLAY [variable precedence test] **************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
[WARNING]: Platform darwin on host 127.0.0.1 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
ok: [127.0.0.1]
ERROR! an undefined variable was found when attempting to template the vars_files item 'vars/{{ env }}.yml'
The error appears to be in '/tmp/exercises/ansible/playbooks/example_play.yml': line 5, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
vars_files:
- "vars/{{ env }}.yml"
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"