linux - ansible设置文件描述符值,例如nproc和nofile linux

标签 linux ansible-2.x

我有下面的 Playbook 来为 Linux 中的用户设置文件描述符值,我有下面的代码,经过测试并且工作正常,我正在寻找是否使用诸如 vars 之类的东西来缩短代码。

准确地说,我想使用模块 pam_limits one 并同时涵盖增加 nofilesnproc 值的操作。

---
- name: Setting File-descriptor Values for db_user
  hosts: all
   become: yes
   become_method: sudo
   become_user: root
   tasks:
    - name: Setting-up file-max limit
      sysctl:
       name: fs.file-max
       value: '1618107'
       state: present
       reload: yes

    - name: setting-up nofile limit
      pam_limits:
       domain: db_user
       limit_type: "{{ item }}"
       limit_item: nofile
       value: '260000'
      loop:
       - soft
       - hard

    - name: setting-up nproc limit
      pam_limits:
       domain: db_user
       limit_type: "{{ item }}"
       limit_item: nproc
       value: '16383'
      loop:
       - soft
       - hard
...

最佳答案

一种方法,您可以按如下方式使用循环但是,我看到您的限制值是相同的,因此您可以更好地使用 - 正如我在下面的评论中提到的。

---
- name: Setting File-descriptor Values for db_user
  hosts: all
  become: yes
  become_method: sudo
  become_user: root
  tasks:
    - name: Setting-up file-max limit
      sysctl:
        name: fs.file-max
        value: 1618107
        state: present
        reload: yes
    - name: Setting-up nofles and nproc limit for db_user
      pam_limits:
        domain: db_user
        limit_type: "{{item.limit_type}}"
        limit_item: "{{item.limit_item}}"
        value: "{{item.value}}"
      loop:
        # Add nofile and nproc, both soft and hard, limit for the user db_user with a comment.
        # Type "-" for enforcing both soft and hard resource limits together for more details read `man limits.conf`.
        - { limit_type: '-', limit_item: 'nofile', value: 260000 }
        - { limit_type: '-', limit_item: 'nproc', value: 16383 }

关于linux - ansible设置文件描述符值,例如nproc和nofile linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63690755/

相关文章:

path - Ansible - 如何评估 role_path 变量

linux - 是由 xlib 实现的剪贴板还是由单独的应用程序实现

c# - 在 Windows 中监听端口是否比在 Linux 中慢?

linux - 从 bash 脚本返回错误的 BASH 变量

azure - 如何根据 set_facts 将多个 ansible 条件合并为一个

Ansible 检查字典列表中是否存在键/值对

Ansible 主机变量未定义

linux - TCP流中继

linux - 如何使用 apt-cyp 在 cygwin 中安装 PANDAseq?

amazon-ec2 - 使用 Ansible 通过 instance_interruption_behavior 供应多个 spot 实例