大家好,也许您可以帮助我解决这个问题。我试图以我的apache角色创建一些文件夹。(该角色最初来自geerlenguy)
这是我的主机vars文件的一部分:
apache_vhosts:
- servername: myhost.com
documentroot: "/var/www/html/web"
extra_parameters: |
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/server-status.*
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
<Directory "/var/www/html/web">
AuthType Basic
Require valid-user
AuthName "Please authenticate"
AuthUserFile /var/www/html/.htpasswd
</Directory>
- servername: secondhost.com
documentroot: "/var/www/learning/web"
extra_parameters: |
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/server-status.*
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
<Directory "/var/www/learning/web">
AuthType Basic
Require valid-user
AuthName "Please authenticate"
AuthUserFile /var/www/learning/.htpasswd
</Directory>
此刻我的任务看起来像这样:
- name: Create Apache vhost Folders
file:
path: "{{ item.0.documentroot }}"
state: directory
mode: '0755'
owner: root
group: root
with_items:
- apache_vhosts
但是这对我来说似乎是垃圾。由于此错误,我无法使它工作:
fatal: [webserver.company.com]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The error was: 'unicode object' has no attribute 'documentroot'
你们能告诉我如何在我的任务中正确访问documentroot
变量吗?会很棒!
尝试一下
- name: Create Apache vhost Folders
file:
path: "{{ item.documentroot }}"
...
with_items: "{{ apache_vhosts }}"
loop: "{{ apache_vhosts }}"
- debug:
msg: "{{ item.documentroot }}"
loop: "{{ apache_vhosts }}"
给予
"msg": "/var/www/html/web"
"msg": "/var/www/learning/web"