ansible - 使用 with_items 时错误项未定义
问题描述
我正在尝试创建一个新的剧本,它应该在现有文件中添加一些行。不幸的是,我的剧本不起作用。
---
-
name: 'Playbook to update limits in 20-nproc.conf'
remote_user: lwa
strategy: free
gather_facts: no
become: yes
hosts: "{{ target }}"
tasks:
-
name: 'Updating limits for oracle user for Oracle DB installation'
lineinfile:
path: /etc/security/limits.d/20-nproc.conf
line: '{{ item }}'
state: present
insertafter: EOF
backup: yes
create: no
owner: root
group: root
mode: '644'
with_items:
- '#<domain> <type> <item> <value>'
- 'oracle soft nofile 4096'
- 'oracle hard nofile 63536'
- 'oracle soft nproc 2047'
- 'oracle hard nproc 16384'
- 'oracle soft stack 10240'
- 'oracle hard stack 32768'
解决方案
我终于明白了。我使用了 blockinfile 模块而不是 lineinfile。
---
-
name: 'Playbook to update limits in 20-nproc.conf'
remote_user: lwa
strategy: free
gather_facts: no
become: yes
hosts: "{{ target }}"
tasks:
-
name: 'Insert/Update limits for oracle user for Oracle DB installation'
blockinfile:
path: /etc/security/limits.d/20-nproc.conf
block: |
#<domain> <type> <item> <value>
oracle soft nofile 4096
oracle hard nofile 63536
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft stack 10240
oracle hard stack 32768
state: present
insertafter: EOF
backup: yes
create: no
owner: root
group: root
mode: '644'
推荐阅读
- reactjs - 将 redux 表单与 react 标签自动完成集成
- symfony - Symfony 4:如何使用文件系统组件的删除功能从文件夹中删除文件
- r - Centos 8、R、EPEL 8、dplyr --> `GLIBCXX_3.4.26' 未找到
- android - JSON数组在android上显示空白屏幕
- java - maven 无法解析 jmonkeyengine 的依赖关系
- javascript - Websocket 服务器和 npm 在 localhost 上启动
- firebase - 在本地运行 firebase 触发事件
- reactjs - 组件渲染 8 次
- bash - 如何从 bash 脚本中获取 perl 退出值
- sendmail - 如何将 sendmail 配置为仅接收来自一个收件人的电子邮件并拒绝其他所有内容?