【发布时间】:2019-11-05 11:42:17
【问题描述】:
我正在尝试使用 Ansible 来设置 Apache 虚拟主机和数据库,但并非所有 Vhost 都会有数据库(1 个或更多)。
我已经尝试了很多,也尝试从 here 进行调整,但没有任何效果。我在很长一段时间内做了很多尝试和错误并想出了这个:
我的host_vars(摘录):
web_vhosts:
- vhost:
name: domain1.tld
enabled: true
serveradmin_email: info@example.org
https: true
redirect_to_https: true
dns_a_record: 1.2.3.4
update_dns: false
- vhost:
name: domain2.tld
enabled: true
serveradmin_email: info@example.org
https: true
redirect_to_https: true
dns_a_record: 1.2.3.4
update_dns: false
mysql:
- name: wordpress1
user: myuser
password: secret
这是我的距离:
- name: Ensure databases
mysql_db:
name: "{{ item.1.name }}"
state: present
login_unix_socket: /var/run/mysqld/mysqld.sock
when: item.0.mysql is defined
with_subelements:
- "{{ web_vhosts }}"
- "mysql"
哪些错误:
fatal: [examplehost]: FAILED! => {"msg": "could not find 'mysql' key in iterated item '{'vhost': {'name': 'domain1.tld', 'enabled': True, 'serveradmin_email': 'info@example.org', 'https': True, 'redirect_to_https': True, 'dns_a_record': '1.2.3.4', 'update_dns': False}}'"}
谁能帮我理解问题所在?
【问题讨论】:
标签: ansible