Ansible任务包含一个带有未定义变量的选项



我正在使用ansible部署网站。但我得到了这个错误:

fatal: [lxc-server]: FAILED! => {"failed": true, "msg": "The task includes an option with an undefined variable. The error was: [{u'authorized_keys': u'{{ delivery_authorized_keys }}', u'group': u'{{ magento_webserver_group }}', u'name': u'{{ magento_project_user }}'}]: {{ http_group_name }}: 'http_group_name' is undefinednnThe error appears to have been in '/home/jredor/projets/webstore/architecture/provisioning/provision.yml': line 32, column 7, but maynbe elsewhere in the file depending on the exact syntax problem.nnThe offending line appears to be:nnn    - name: "Prepare the delivery_users object"n      ^ herennexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>nexception: [{u'authorized_keys': u'{{ delivery_authorized_keys }}', u'group': u'{{ magento_webserver_group }}', u'name': u'{{ magento_project_user }}'}]: {{ http_group_name }}: 'http_group_name' is undefined"}

我知道有一些东西没有定义,但问题是,它是由其他人开发的,应该可以完美地工作,而这个其他人已经不在了。这是规定。yml:

---
# load variables for each servers
- hosts:
- dbservers
- cacheservers
- searchservers
- webservers
vars:
ansible_user: "root"
tasks:
- include: includes/include-vars.yml
# Prepare the delivery authorized keys
- hosts:
- dbservers
- cacheservers
- searchservers
- webservers
connection: local
vars:
ansible_user: "root"
tmp_delivery_users:
- name:   "{{ magento_project_user }}"
group:  "{{ magento_webserver_group }}"
authorized_keys: "{{ delivery_authorized_keys }}"
tasks:
- name: "Prepare the list of the authorized keys for delivery - Extra Keys"
set_fact: delivery_authorized_keys="{{ delivery_authorized_extra_keys }}"
- name: "Prepare the delivery_users object"
set_fact: delivery_users="{{ tmp_delivery_users }}"
# add hosts alias on Servers
- hosts:
- dbservers
- cacheservers
- searchservers
- webservers
vars:
ansible_user: "root"
tasks:
- include: includes/init-hosts.yml
with_items: "{{ specific_hosts|default([]) }}"
# add magento hosts alias on WebServers
- hosts:
- webservers
vars:
ansible_user: "root"
tasks:
- include: includes/init-hosts.yml
with_items: "{{ magento_server_alias|default([]) }}"
# Generic behaviors on all servers
- hosts:
- dbservers
- cacheservers
- searchservers
- webservers
vars:
ansible_user: "root"
roles:
- role: ansible-basicserver
# Generic usage of the ansible roles - DB Server
- hosts: dbservers
vars:
ansible_user: "root"
roles:
- role: ansible-mysql-server
# Generic usage of the ansible roles - Cache Server
- hosts: cacheservers
vars:
ansible_user: "root"
roles:
- {
role: ansible-redis,
redis_instance_name: "magento_cache",
redis_setting_port:  "{{ magento_cache_port }}",
redis_setting_save:  "{{ redis_setting_save_cache }}"
}
- {
role: ansible-redis,
redis_instance_name: "magento_session",
redis_setting_port:  "{{ magento_cache_session_port }}",
redis_setting_save:  "{{ redis_setting_save_session }}"
}
# Generic usage of the ansible roles - Search Server
- hosts: searchservers
vars:
ansible_user: "root"
roles:
- role: ansible-elasticsearch
# Prepare php parameters
- hosts: webservers
vars:
ansible_user: "root"
tasks:
- include: includes/prepare-php-parameters.yml
# Generic usage of the ansible roles - Webserver Server
- hosts: webservers
vars:
ansible_user: "root"
roles:
- role: ansible-php
- role: ansible-apache
- role: ansible-varnish
- role: ansible-nginx
# Specific usage of the ansible roles - Webserver Server - Dev Tools
- hosts: webservers
vars:
ansible_user: "root"
roles:
- { role: ansible-npm, when: magento_install_maildev or magento_install_grunt }
- { role: ansible-maildev, when: magento_install_maildev }
tasks:
- name: "Install NPM package: grunt-cli"
npm: name="grunt-cli" global=yes
when: magento_install_grunt
- name: "Add delivery user in groups"
user:
name: "{{ magento_project_user }}"
groups: "{{ magento_delivery_groups }}"
- name: "Create {{ magento_source_path }} folder"
file:
path:  "{{ magento_source_path }}"
state: directory
owner: "{{ magento_project_user }}"
group: "{{ magento_project_group }}"
mode:  "u=rwX,g=rX,o=rX"
# Specific task for Magento 2
- name: "Check if Magento app/etc/env.php exists"
stat:
path: "{{ magento_source_path }}/app/etc/env.php"
register: magento_app_etc_env
- name: "Update app/etc/env.php configuration file"
template:
src: "templates/magento/env.php.j2"
dest: "{{ magento_source_path }}/app/etc/env.php"
owner: "{{ magento_project_user }}"
group: "{{ magento_webserver_group }}"
mode: "u=rw,g=rw,o=r"
vars:
magento_cache_database: "{{ magento_cache_database_for_run }}"
when: magento_app_etc_env.stat.exists
# Update permissions
- include: includes/permissions-tasks-full.yml

错误在那里触发:

- name: "Prepare the delivery_users object"
set_fact: delivery_users="{{ tmp_delivery_users }}"

所以,正如我所说,我理解http_group_name是未定义的,但我如何定义它呢?如何调试?

我注意到http_group_name是在distro vars中定义的,其中每个distri都有一个yml文件。有CentOS-7、Debian-8、Debian-9、RadHat-7和Ubuntu-16.04。但我的发行版是Ubuntu 20.04。可能是问题吗?我应该创建一个Ubuntu-20.04.yml吗?感谢

编辑:我的env.php.j2

{% set document_root_is_pub = 'false' %}
{% if magento_mode == 'production' %}{% set document_root_is_pub = 'true' %}{% endif %}
<?php
return array(
'db' => array(
'connection' => array(
'default' => array(
'host' => '{{ magento_db_host }}',
'dbname' => '{{ magento_db_name }}',
'username' => '{{ magento_db_user }}',
'password' => '{{ magento_db_password }}',
'model' => 'mysql4',
'engine' => 'innodb',
'initStatements' => 'SET NAMES utf8;',
'active' => '1',
'driver_options' => array(PDO::MYSQL_ATTR_LOCAL_INFILE => true),
),
),
'table_prefix' => '{{ magento_db_table_prefix }}',
),
'backend' => array(
'frontName' => '{{ magento_backend_frontname }}',
),
'install' => array(
'date' => '{{ magento_install_date }}',
),
'crypt' => array(
'key' => '{{ magento_crypt_key }}',
),
'session' => array(
'save' => 'redis',
'redis' => array(
'host' => '{{ magento_cache_session_host }}',
'port' => '{{ magento_cache_session_port }}',
'database' => '{{ magento_cache_session_database }}',
'disable_locking' => '1',
),
),
'cache' => array(
'frontend' => array(
'default' => array(
'backend' => 'Cm_Cache_Backend_Redis',
'id_prefix' => '{{ magento_cache_id_prefix }}',
'backend_options' => array(
'server' => '{{ magento_cache_host }}',
'port' => '{{ magento_cache_port }}',
'persistent' => '',
'database' => '{{ magento_cache_database }}',
'force_standalone' => '0',
'connect_retries' => '1',
'read_timeout' => '10',
'automatic_cleaning_factor' => '0',
'compress_data' => '1',
'compress_tags' => '1',
'compress_threshold' => '20480',
'compression_lib' => 'gzip',
),
),
),
),
'http_cache_hosts' => array(
{% set loop_index = 0 %}
{% for host in magento_http_cache_hosts %}
{{ loop_index }} => array(
'host' => '{{ host.host }}',
'port' => '{{ host.port }}',
),
{% set loop_index = loop_index + 1 %}
{% endfor %}
),
'MAGE_MODE' => '{{ magento_mode }}',
'directories' => array(
'document_root_is_pub' => {{ document_root_is_pub }},
),
'queue' => array(
'amqp' => array(
'host' => '',
'port' => '',
'user' => '',
'password' => '',
'virtualhost' => '/',
'ssl' => '',
),
),
'resource' => array(
'default_setup' => array(
'connection' => 'default',
),
),
'x-frame-options' => 'SAMEORIGIN',
'cache_types' => array(
'config' => 1,
'layout' => 1,
'block_html' => 1,
'collections' => 1,
'reflection' => 1,
'db_ddl' => 1,
'eav' => 1,
'customer_notification' => 1,
'target_rule' => 1,
'full_page' => 1,
'config_integration' => 1,
'config_integration_api' => 1,
'full_page' => 1,
'translate' => 1,
'config_webservice' => 1,
),
);

我没有任何";http_group_name"在这里。这是错误吗?我应该在那里定义它吗?如果是,我该怎么做?

问题出在发行版上。由于我在我的容器上使用debian 10,我在debian 9上做了一个新容器,它起了作用。

最新更新