如何解决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 undefined\n\nThe error appears to have been in '/home/jredor/projets/webstore/architecture/provisioning/provision.yml': line 32,column 7,but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: \"Prepare the delivery_users object\"\n ^ here\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: [{u'authorized_keys': u'{{ delivery_authorized_keys }}',u'name': u'{{ magento_project_user }}'}]: {{ http_group_name }}: 'http_group_name' is undefined"}
我知道有一些未定义的东西,但是事实是,它是由其他人开发的,应该可以正常工作,而这个其他人已经不在了。这是Provision.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是未定义的,但是我该如何定义呢?我该如何调试?
我注意到在distro-vars中定义了http_group_name,其中每个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,'translate' => 1,'config_webservice' => 1,);
我这里没有任何“ http_group_name”。这是错误吗?我应该在那里定义吗?如果是这样,我该怎么办?
解决方法
问题是发行版。自从我在容器上使用debian 10以来,我在debian 9上做了一个新的容器,它起作用了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。