小编Ale*_*van的帖子

Ansible:在文件的现有行中插入单个单词

我必须使用Ansible模块来编辑/ etc/ssh/sshd_config文件 - 每次创建新用户时我都想在这两行中追加它:

AllowUsers root osadmin <new_user>
AllowGroups root staff <new_group>
Run Code Online (Sandbox Code Playgroud)

此时我正在使用shell模块执行sed命令,但如果可能的话,我想使用lineinfile

- shell: "sed -i '/^Allow/ s/$/ {{ user_name }}/' /etc/ssh/sshd_config"
Run Code Online (Sandbox Code Playgroud)

任何建议都将得到真诚的感谢.

sshd ansible

9
推荐指数
2
解决办法
2万
查看次数

带有时间戳的Ansible模板

我试图找出是否有方法在Ansible中为模板文件添加时间戳,这样每次我运行使用某个模板的Ansible playbook时,它会在目标文件中添加执行playbook的时间.

例如,我正在使用Ansible模板配置文件,我希望它在目标计算机上显示第一行的时间戳...

例如

cat something.conf_template
some config lines
Run Code Online (Sandbox Code Playgroud)

模板化后:

- template: src=/mytemplates/something.conf_template dest=/etc/something.conf owner=smth group=smth mode=0644
Run Code Online (Sandbox Code Playgroud)

内容应该是

cat something.conf
#in this comment is the timestamp, format irrelevant
some config lines
Run Code Online (Sandbox Code Playgroud)

你知道任何可以做到这一点的ansible模块吗?

ansible ansible-playbook

4
推荐指数
1
解决办法
2711
查看次数

标签 统计

ansible ×2

ansible-playbook ×1

sshd ×1