У меня есть playbook, который запускает настраиваемую задачу для настройки vhost nginx:
tasks:
- include: tasks/tweaks.yml
В этой пьесе следующие var_files
используются:
vars_files:
- ../config.yml
В config.yml
У меня есть следующий список, содержащий информацию о vhost:
nginx_hosts_custom:
- server_name: "mytest.dev"
root: /drupal/www/mytest
is_php: true
common_config: true
remote_host: "12.34.56.78"
remote_root: "/web/ubuntu/www/mytest/public"
pem: "mytest.pem"
В пределах tweaks.yml
Имею следующее:
- name: "Extra Nginx hosts for the Drupal sites"
template:
src: ../templates/nginx-vhost.conf.j2
dest: "{{ nginx_vhost_path }}/{{ item.server_name.split(' ')[0] }}.conf"
force: yes
owner: root
group: root
mode: 0644
with_items: nginx_hosts_custom
notify: restart nginx
when: drupalvm_webserver == 'nginx'
Раньше это работало отлично, но теперь я получаю следующую ошибку при запуске предоставления:
fatal: [owenvm]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'unicode object' has no attribute 'server_name'\n\nThe error appears to have been in /tasks/tweaks.yml': line 20, 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: \"Extra Nginx hosts for the Drupal sites\"\n ^ here\n"}
Итак, переменная server_name
не подхватывается - может кто подскажет исправление?
Голые переменные в with_items
, лайк with_items: nginx_hosts_custom
устарели с Ansible 2.0 и полностью не поддерживаются с 2.2.
Вы должны использовать with_items: "{{ nginx_hosts_custom }}"
В tweaks.yml
- name: "Extra Nginx hosts for the Drupal sites"
template:
src: ../templates/nginx-vhost.conf.j2
dest: "{{ nginx_vhost_path }}/{{ item['server_name'].split(' ') | first }}.conf"
force: yes
owner: root
group: root
mode: 0644
with_items: nginx_hosts_custom
notify: restart nginx
when: drupalvm_webserver == 'nginx'
Кроме того, шаблон обычно знает, что нужно искать ../templates
(по крайней мере, при использовании ролей). Вы уверены, что вам нужно указать относительный путь? Может быть достаточно придерживаться имени файла вашего шаблона.
В зависимости от версии Ansible, with_items
может потребоваться установить на '{{ nginx_host_custom }}'
. Хотя, судя по вашему сообщению об ошибке, это не наш случай.
Я также рекомендую убедиться nginx_hosts_custom
определяется в вашем when
пункт, например:
when: drupal_webserver == 'nginx' and nginx_hosts_custom is defined and nginx_hosts_custom != False