ansible - 如何使用 ansible 配置远程主机 journal.conf 文件?
问题描述
我正在尝试使用 ansible 配置树莓派 journalctl。我尝试使用一些看似过于复杂且最终没有交付的 ansible-galaxy 角色。
我只是想配置 /etc/systemd/journald.conf 文件。
我可以用 ansible.builtin.systemd 或任何其他建议来做吗?
解决方案
您只需要一个剧本和一个模板文件。
- myproject/changejournald.yml # 你的剧本
- myproject/journald.conf.j2 # 一个 jinja2 模板,'journald.conf as you want it'
在 changejournald.yml
---
- name: upload new template
template:
src: 'journald.conf.j2'
dest: '/etc/systemd/journald.conf'
become: true #<-- unless you are connecting as root
- name: reload systemd-journald
systemd:
name: systemd-journald
state: restart
become: true
像这样的东西应该有效吗?
还有其他模块,如 lineinfile 或 blockinfile 可能更有用,具体取决于您打算如何配置它。