我正在尝试在 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`
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在我的剧本中运行 shell 命令来提取命令的结果。的输出
- debug: msg="{{ dblist.stdout_lines }}"
Run Code Online (Sandbox Code Playgroud)
是
ok: [host] => {
"msg": [
"inst1:db1"
"inst1:db2"
"inst1:db3"
"inst2:db4"
"inst2:db3"
]
}
Run Code Online (Sandbox Code Playgroud)
我需要以一种允许我运行下一个剧本的格式存储该值,同时考虑 item.0 的值作为 inst1 和 item.1 的值作为 db2 等等。
现在
- debug: msg="{{ item.0 }} has a value {{ item.1 }}"
with_items: "{{ dblist.stdout_lines }}"
Run Code Online (Sandbox Code Playgroud)
给出像这样的值
ok: [host] => (item=inst1:db1) => {
"msg": "i has a value n"
}
ok: [host] => (item=inst1:db2) => {
"msg": "i has a value n"
Run Code Online (Sandbox Code Playgroud)
谢谢。
我正在尝试通过使用 Ansible 生成 /etc/exports 文件来动态配置系统中的多个 NFS 服务器。我希望能够使用 jinja2 模板来做到这一点。这是 jinja2 模板,我无法根据我的导出列表找出它。
我在 nfs 角色中定义了以下变量:
site_nfs_servers: ['ansibletarget1', 'ansibletarget2']
exports:
- server: "ansibletarget1"
shares:
- path: "/my/first/share/path"
client: "*"
options: "rw,sync"
- path: "/my/second/share/path"
client: "*"
options: "rw,sync,root_squash"
- server: "ansibletarget2"
shares:
- path: "/another/shared/path/different/server"
client: "*"
options: "ro,sync"
Run Code Online (Sandbox Code Playgroud)
然后我有以下 ansible play 来生成模板:
- name: Generate the exports file.
template:
src: exports.j2
dest: /etc/exports
owner: root
group: root
mode: '0750'
Run Code Online (Sandbox Code Playgroud)
我的模板目前如下所示:
{% for export in exports %}
{% if ansible_hostname in export.server …
Run Code Online (Sandbox Code Playgroud) 使这个任务第一次就能工作:
- name: Initialize the Database
command: /usr/pgsql-9.6/bin/postgresql96-setup initdb
Run Code Online (Sandbox Code Playgroud)
如果第二次运行,会出现错误:
致命:[192.168.0.1]:失败!=> {“更改”:true,“cmd”:[“/usr/pgsql-9.6/bin/postgresql96-setup”,“initdb”],“delta”:“0:00:00.017590”,“结束”: "2019-12-11 06:08:49.999631", "msg": "非零返回码", "rc": 1, "start": "2019-12-11 06:08:49.982041", "stderr ": "", "stderr_lines": [], "stdout": "数据目录不为空!", "stdout_lines": ["数据目录不为空!"]}
如果它已经在服务器上初始化了数据库,如何避免运行此任务?
我创建了一个简单的 Ansible 剧本:
---
- hosts: all
tasks:
- name: Install Icinga2 on Windows
include_role:
name: my.icinga2.role
apply:
tags:
- install-icinga2
Run Code Online (Sandbox Code Playgroud)
该角色包含以下任务文件:
---
- include_tasks: vars.yml
tags: ['always']
- include_tasks: install.yml
tags: ['install-icinga2-stack', 'install-icinga2']
- include_tasks: ido-install.yml
when: icinga2_ido_enable == true
tags: ['install-icinga2-stack', 'install-icinga2-ido']
- include_tasks: configure.yml
tags: ['install-icinga2-stack']
[...]
Run Code Online (Sandbox Code Playgroud)
这是我执行剧本时的结果:
me@ansible:~/ansible$ ansible-playbook plays/icinga2-client-win.yml -i staging.ini --limit windows
PLAY [all] ***************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************
ok: [my.windows.client]
TASK [Include variables for Icinga 2] ********************************************************************************************
ok: [my.windows.client]
TASK [set_fact] ******************************************************************************************************************
skipping: …
Run Code Online (Sandbox Code Playgroud)