ansible - Ansible 错误是:'unicode object'没有属性
问题描述
嘿伙计们,也许你可以帮助我解决这个问题。我试图在我的 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
在我的任务中正确访问 var 吗?会很好!
解决方案
尝试这个
- 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"
推荐阅读
- c++ - cv::detail::MultiBandBlender 照片末尾出现奇怪的白色条纹
- airflow - 通过for循环在动态生成的任务之后执行单个任务
- javascript - 无法在高图中的 x 轴上显示日期
- excel - 如果通过 url 链接,Excel 可以显示图像吗?
- java - 在 lambda aws 测试期间,抛出类未找到异常
- javascript - JavaScript 复制 2 个具有其他 ID 的相同脚本将不起作用
- php - 无法用 $_GET 数组中的零值填充单元格
- numpy - argsort -- 根据之前的获胜者打破平局
- python - 如果条件为真,则在另一个视图中调用详细视图
- r - 如何在R中获得第一次出现的字符