Ansible playbook,with_items倍数变量的难度

时间:2015-08-04 14:40:21

标签: yaml ansible-playbook

我使用ansible来配置服务器。我必须看看是否存在某些行,如果我必须更改它们,那么我使用lineinfile模块。为了让代码更干净,我会使用像这样的with_items:

- name: Postegresql configuration
  lineinfile: dest={{ item.dest }} line={{ item.line }} regexp={{ item.regexp }}
  with_items:
    - { dest: '/var/lib/pgsql/data/postgresql.conf', line: 'port = 5433', regexp: '^port =' }
    - { dest: '/var/lib/pgsql/data/postgresql.conf', line: 'log_truncate_on_rotation = on', regexp: '^log_truncate_on_rotation =' }
    - { dest: '/var/lib/pgsql/data/postgresql.conf', line: 'log_rotation_age = 1d', regexp: '^log_rotation_age =' }
    - { dest: '/var/lib/pgsql/data/postgresql.conf', line: 'log_rotation_size = 0MB', regexp: '^log_rotation_size =' }
  notify: restart postgresql
  tags: verif

但它不起作用。我他=这个错误:

a duplicate parameter was found in the argument string ()

我这是一个语法错误,你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

尝试在您使用的任何插入变量周围加上引号。这将确保将它们作为一个整体对待并按照您的意愿进行解析。

lineinfile: dest="{{ item.dest }}" line="{{ item.line }}" regexp="{{ item.regexp }}"