If you need to configure a set of unique property=value lines, I recommend a more concise loop. For example:
- name: Configure kernel parameters
lineinfile:
dest: /etc/sysctl.conf
regexp: "^{{ item.property | regex_escape() }}="
line: "{{ item.property }}={{ item.value }}"
with_items:
- { property: 'kernel.shmall', value: '2097152' }
- { property: 'kernel.shmmax', value: '134217728' }
- { property: 'fs.file-max', value: '65536' }
Using a dict as suggested by Alix Axel and adding automatic removing of matching commented out entries,
- name: Configure IPV4 Forwarding
lineinfile:
path: /etc/sysctl.conf
regexp: "^#? *{{ item.key | regex_escape() }}="
line: "{{ item.key }}={{ item.value }}"
with_dict:
'net.ipv4.ip_forward': 1