属性不存在执行ansible playbook时出错
我试图执行现有ansible playbook,但出现以下错误:属性不存在执行ansible playbook时出错,ansible,Ansible,我试图执行现有ansible playbook,但出现以下错误: fatal: [default]: FAILED! => {"failed": true, "msg": "ERROR! 'unicode object' has no attribute 'regexp'"} 执行ansible剧本的这一部分时: - name: "Add access to pg_hba.conf for DB users" become: yes become_user: postgres
fatal: [default]: FAILED! => {"failed": true, "msg": "ERROR! 'unicode object' has no attribute 'regexp'"}
执行ansible剧本的这一部分时:
- name: "Add access to pg_hba.conf for DB users"
become: yes
become_user: postgres
lineinfile: dest="{{ PATH_PG_HBA }}" regexp="{{ item.regexp }}" line="{{ item.line }}" state=present create=yes
with_items: "{{ DATABASE_ACL }}"
notify: restart postgresql
显然,对象中不存在regexp。但由于我在ansible方面的经验有限,我想知道这是一个与lineinfle参数相关的一般错误还是这个ansible yaml文件的某些特定错误
{DATABASE_ACL}}变量在group_vars文件夹中声明为:
DATABASE_ACL:
- "local {{ DB_NAME }} {{ DB_USER }} md5"
- "host {{ DB_NAME }} {{ DB_USER }} 127.0.0.1/32 md5"
- "host {{ DB_NAME }} {{ DB_USER }} 10.0.2.2/32 md5"
在同一文件夹中声明了DB_名称和DB_用户字符串。组vars中的DATABASE_ACL是字符串列表,循环中的项是unicode字符串。显然,正如您所说,这个错误确切地告诉您这个-unicode字符串没有属性regexp。这个精确的错误可以在ipython中重现,如:
In [1]: a = unicode("some string")
In [2]: a.regexp
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-26893273be72> in <module>()
----> 1 a.regexp
AttributeError: 'unicode' object has no attribute 'regexp'
结果项将是dict,结构为{line:your line,regexp:your regexp},在您的情况下将正常工作。请包括您的数据库ACL变量,以及您在哪里声明的?在剧本里,小组球员,额外球员,库存?@Andrew我编辑了这个问题。
DATABASE_ACL:
- line: "local {{ DB_NAME }} {{ DB_USER }} md5"
regexp: "local"
- line: "host {{ DB_NAME }} {{ DB_USER }} 127.0.0.1/32 md5"
regexp: "host .* 127"
- line: "host {{ DB_NAME }} {{ DB_USER }} 10.0.2.2/32 md5"
regexp: "host .* 10.0.2.2"