Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bryder/7b35447c4efe77e1a9c70c06bd546640 to your computer and use it in GitHub Desktop.
Save bryder/7b35447c4efe77e1a9c70c06bd546640 to your computer and use it in GitHub Desktop.
- vars:
ansible_added_line: "# Line added by ansible "
nofile_limits:
- user: root
limits:
- soft: 65001
- hard: 70001
- user: some_user
limits:
- soft: 65001
- hard: 65001
- tasks:
- name: remove old limits
lineinfile:
dest: /etc/security/limits.conf
regexp: "^{{ item.0.user }}\\s+{{ item.1.keys()[0] }}\\s+nofile\\s+(?!{{ item.1[item.1.keys()[0]] }} {{ ansible_added_line}})"
state: absent
with_subelements:
- "{{ nofile_limits }}"
- limits
- name: add limits
lineinfile:
dest: /etc/security/limits.conf
state: present
line: "{{ item.0.user }} {{ item.1.keys()[0] }} nofile {{ item.1[item.1.keys()[0]] }} {{ ansible_added_line}}"
with_subelements:
- "{{ nofile_limits }}"
- limits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment