我正在尝试在 sysctl.conf 文件的内联模块中添加一个值,我该如何实现?一旦我在提示中输入该值,它就会在 sysctl.conf 文件中更新。
- name: shmmax
prompt: " Please enter the value for kernel.shmmax "
private: false
- name: Set some kernel parameters
lineinfile:
dest: /etc/sysctl.conf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: '^kernel.shmmax', line: 'kernel.shmmax = {{ shmmax }}' }
error is get is.
TASK [Set some kernel parameters] **********************************************************************************************************************************
fatal: [192.168.1.28]: FAILED! => {"msg": "'kernel' is undefined"}
to retry, use: --limit `enter code here`
谢谢
答案1
有暂停模块提示任务内的输入。
例如
- hosts: localhost
tasks:
- pause:
prompt: "Please enter the value for kernel.shmmax "
echo: yes
register: result
- set_fact:
shmmax: "{{ result.user_input }}"
- debug:
var: shmmax
给出(节选)
TASK [pause]
[pause]
Please enter the value for kernel.shmmax :
[ok: [localhost]
TASK [set_fact]
ok: [localhost]
TASK [debug]
ok: [localhost] => {
"shmmax": "new_kernel.shmmax_value"
}
笔记
- 问题中的这部分代码无法工作,因为任务中没有模块
- name: shmmax
prompt: " Please enter the value for kernel.shmmax "
private: false
运行这样的代码将会产生
ERROR! Syntax Error while loading YAML.
mapping values are not allowed in this context
- 变量可以在任何任务中使用,只要它被提示、注册和声明为设置事实。