Mat*_*uba 6 ansible centos7 systemctl
在我的剧本中,我有一个任务来更新audit.rules,然后通知处理程序,该处理程序应重新启动已审计的服务。
task:
- name: 6.6.7 - audit rules configuration
template: src=X/ansible/templates/auditd_rules.j2
dest=/etc/audit/rules.d/audit.rules
backup=yes
owner=root group=root mode=0640
notify:
- restart auditd
handlers:
- name: restart auditd
service: name=auditd state=restarted
Run Code Online (Sandbox Code Playgroud)
当剧本运行时,审核规则将更新,并发出重新启动auditd的请求,但这失败,如下所示。
RUNNING HANDLER [restart auditd] ***********************************************
fatal: [ipX-southeast-2.compute.internal]: FAILED! => {"changed": false, "failed": true, "msg": "Unable to restart service auditd: Failed to restart auditd.service: Operation refused, unit auditd.service may be requested by dependency only.\n"}
Run Code Online (Sandbox Code Playgroud)
当我查看审计的单位定义时,可以看到rejectManualStop = yes。这就是为什么我无法重启服务吗?如何克服这一点以采纳新的审核规则?
systemctl cat auditd.service
# /usr/lib/systemd/system/auditd.service
[Unit]
Description=Security Auditing Service
DefaultDependencies=no
After=local-fs.target systemd-tmpfiles-setup.service
Conflicts=shutdown.target
Before=sysinit.target shutdown.target
RefuseManualStop=yes
ConditionKernelCommandLine=!audit=0
Documentation=man:auditd(8) https://people.redhat.com/sgrubb/audit/
[Service]
ExecStart=/sbin/auditd -n
## To not use augenrules, copy this file to /etc/systemd/system/auditd.service
## and comment/delete the next line and uncomment the auditctl line.
## NOTE: augenrules expect any rules to be added to /etc/audit/rules.d/
ExecStartPost=-/sbin/augenrules --load
#ExecStartPost=-/sbin/auditctl -R /etc/audit/audit.rules
ExecReload=/bin/kill -HUP $MAINPID
# By default we don't clear the rules on exit. To enable this, uncomment
# the next line after copying the file to /etc/systemd/system/auditd.service
#ExecStopPost=/sbin/auditctl -R /etc/audit/audit-stop.rules
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
在Red Hat Bugzilla#1026648和Anisble Issue#22171(github)报告中(大多数)已经对此进行了探讨,讨论和解决。
解析度
service模块参数use=service来强制执行该/sbin/service实用程序,而不是像这样systemd(调用/sbin/systemctl)收集事实值:
- service: name=auditd state=restarted use=service解决方法:
command模块来显式运行服务可执行文件,如下所示:
- command: /sbin/service auditd restart分析-根本原因:
- 这是由auditd.service单元的上游打包引起的问题。
systemctl显然是设计使然,它不会启动/停止/重新启动。- Ansible服务控制功能进一步使其复杂化,该功能使用在收集系统事实并且“ ansible_service_mgr”返回“ systemd”时标识的首选方法。这与用于管理service.unit的实际模块无关。
- 如果在即将进行的更新(ERRATA)中有问题,RHEL开发团队可能会修复
- Ansible开发团队提供了一种解决方法,并且(从2.2版本开始)
service使用use参数更新了模块。
| 归档时间: |
|
| 查看次数: |
12888 次 |
| 最近记录: |