当前位置:   article > 正文

ansible:如何在centos 7上重新启动auditd服务得到关于依赖的错误_auditd.service重启

auditd.service重启

在我的剧本中,我有一个更新 audit.rules 的任务,然后通知应该重新启动 auditd 服务的处理程序。

  1. task:
  2. - name: 6.6.7 - audit rules configuration
  3. template: src=X/ansible/templates/auditd_rules.j2
  4. dest=/etc/audit/rules.d/audit.rules
  5. backup=yes
  6. owner=root group=root mode=0640
  7. notify:
  8. - restart auditd
  9. handlers:
  10. - name: restart auditd
  11. service: name=auditd state=restarted

当 playbook 运行时,会更新审计规则并请求重新启动 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"} 

当我查看auditd 的单元定义时,我可以看到rejectManualStop=yes。这就是我无法重新启动服务的原因吗?一个人如何来接受新的审计规则?
  1. systemctl cat auditd.service
  2. # /usr/lib/systemd/system/auditd.service
  3. [Unit]
  4. Description=Security Auditing Service
  5. DefaultDependencies=no
  6. After=local-fs.target systemd-tmpfiles-setup.service
  7. Conflicts=shutdown.target
  8. Before=sysinit.target shutdown.target
  9. RefuseManualStop=yes
  10. ConditionKernelCommandLine=!audit=0
  11. Documentation=man:auditd(8) https://people.redhat.com/sgrubb/audit/
  12. [Service]
  13. ExecStart=/sbin/auditd -n
  14. ## To not use augenrules, copy this file to /etc/systemd/system/auditd.service
  15. ## and comment/delete the next line and uncomment the auditctl line.
  16. ## NOTE: augenrules expect any rules to be added to /etc/audit/rules.d/
  17. ExecStartPost=-/sbin/augenrules --load
  18. #ExecStartPost=-/sbin/auditctl -R /etc/audit/audit.rules
  19. ExecReload=/bin/kill -HUP $MAINPID
  20. # By default we don't clear the rules on exit. To enable this, uncomment
  21. # the next line after copying the file to /etc/systemd/system/auditd.service
  22. #ExecStopPost=/sbin/auditctl -R /etc/audit/audit-stop.rules
  23. [Install]
  24. WantedBy=multi-user.target

最佳答案

这已在 Red Hat Bugzilla #1026648 中进行了探索、讨论和解决(大部分)。和 Anisble Issue # 22171 (github)报告。

分辨率

  • 使用 ansible service模块参数use=service强制执行 /sbin/service实用程序而不是 systemd 的聚集事实值(调用 /sbin/systemctl )像这样:
  • - service: name=auditd state=restarted use=service
  • Example playbook (pastebin.com)
  • 解决方法:
  • 使用 ansible command模块来显式运行服务可执行文件,如下所示:
  • - command: /sbin/service auditd restart
  • 分析——根本原因:
     
    • This is an issue created by upstream packaging of auditd.service unit. It will not start/stop/restart when acted upon by systemctl, apparently by design.
    • It is further compounded by the Ansible service control function, which uses the preferred method identified when system facts are gathered and "ansible_service_mgr" returns "systemd". This is regardless of the actual module used to manage the service.unit.
    • RHEL dev team may fix if considered a problem in upcoming updates (ERRATA)
    • Ansible dev team has offered a workaround and (as of 2.2) updated the service module with the use parameter.

关于ansible:如何在centos 7上重新启动auditd服务得到关于依赖的错误,我们在Stack Overflow上找到一个类似的问题: centos7 - ansible: how to restart auditd service on centos 7 get error about dependency - Stack Overflow

在我的剧本中,我有一个更新 audit.rules 的任务,然后通知应该重新启动 auditd 服务的处理程序。

  1. task:
  2. - name: 6.6.7 - audit rules configuration
  3. template: src=X/ansible/templates/auditd_rules.j2
  4. dest=/etc/audit/rules.d/audit.rules
  5. backup=yes
  6. owner=root group=root mode=0640
  7. notify:
  8. - restart auditd
  9. handlers:
  10. - name: restart auditd
  11. service: name=auditd state=restarted

当 playbook 运行时,会更新审计规则并请求重新启动 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"} 

当我查看auditd 的单元定义时,我可以看到rejectManualStop=yes。这就是我无法重新启动服务的原因吗?一个人如何来接受新的审计规则?
  1. systemctl cat auditd.service
  2. # /usr/lib/systemd/system/auditd.service
  3. [Unit]
  4. Description=Security Auditing Service
  5. DefaultDependencies=no
  6. After=local-fs.target systemd-tmpfiles-setup.service
  7. Conflicts=shutdown.target
  8. Before=sysinit.target shutdown.target
  9. RefuseManualStop=yes
  10. ConditionKernelCommandLine=!audit=0
  11. Documentation=man:auditd(8) https://people.redhat.com/sgrubb/audit/
  12. [Service]
  13. ExecStart=/sbin/auditd -n
  14. ## To not use augenrules, copy this file to /etc/systemd/system/auditd.service
  15. ## and comment/delete the next line and uncomment the auditctl line.
  16. ## NOTE: augenrules expect any rules to be added to /etc/audit/rules.d/
  17. ExecStartPost=-/sbin/augenrules --load
  18. #ExecStartPost=-/sbin/auditctl -R /etc/audit/audit.rules
  19. ExecReload=/bin/kill -HUP $MAINPID
  20. # By default we don't clear the rules on exit. To enable this, uncomment
  21. # the next line after copying the file to /etc/systemd/system/auditd.service
  22. #ExecStopPost=/sbin/auditctl -R /etc/audit/audit-stop.rules
  23. [Install]
  24. WantedBy=multi-user.target

最佳答案

这已在 Red Hat Bugzilla #1026648 中进行了探索、讨论和解决(大部分)。和 Anisble Issue # 22171 (github)报告。

分辨率

  • 使用 ansible service模块参数use=service强制执行 /sbin/service实用程序而不是 systemd 的聚集事实值(调用 /sbin/systemctl )像这样:
  • - service: name=auditd state=restarted use=service
  • Example playbook (pastebin.com)
  • 解决方法:
  • 使用 ansible command模块来显式运行服务可执行文件,如下所示:
  • - command: /sbin/service auditd restart
  • 分析——根本原因:
     
    • This is an issue created by upstream packaging of auditd.service unit. It will not start/stop/restart when acted upon by systemctl, apparently by design.
    • It is further compounded by the Ansible service control function, which uses the preferred method identified when system facts are gathered and "ansible_service_mgr" returns "systemd". This is regardless of the actual module used to manage the service.unit.
    • RHEL dev team may fix if considered a problem in upcoming updates (ERRATA)
    • Ansible dev team has offered a workaround and (as of 2.2) updated the service module with the use parameter.

关于ansible:如何在centos 7上重新启动auditd服务得到关于依赖的错误,我们在Stack Overflow上找到一个类似的问题: centos7 - ansible: how to restart auditd service on centos 7 get error about dependency - Stack Overflow

在我的剧本中,我有一个更新 audit.rules 的任务,然后通知应该重新启动 auditd 服务的处理程序。

  1. task:
  2. - name: 6.6.7 - audit rules configuration
  3. template: src=X/ansible/templates/auditd_rules.j2
  4. dest=/etc/audit/rules.d/audit.rules
  5. backup=yes
  6. owner=root group=root mode=0640
  7. notify:
  8. - restart auditd
  9. handlers:
  10. - name: restart auditd
  11. service: name=auditd state=restarted

当 playbook 运行时,会更新审计规则并请求重新启动 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"} 

当我查看auditd 的单元定义时,我可以看到RejectManualStop=yes。这就是我无法重新启动服务的原因吗?一个人如何来接受新的审计规则?
  1. systemctl cat auditd.service
  2. # /usr/lib/systemd/system/auditd.service
  3. [Unit]
  4. Description=Security Auditing Service
  5. DefaultDependencies=no
  6. After=local-fs.target systemd-tmpfiles-setup.service
  7. Conflicts=shutdown.target
  8. Before=sysinit.target shutdown.target
  9. RefuseManualStop=yes
  10. ConditionKernelCommandLine=!audit=0
  11. Documentation=man:auditd(8) https://people.redhat.com/sgrubb/audit/
  1. [Service]
  2. ExecStart=/sbin/auditd -n
  3. ## To not use augenrules, copy this file to /etc/systemd/system/auditd.service
  4. ## and comment/delete the next line and uncomment the auditctl line.
  5. ## NOTE: augenrules expect any rules to be added to /etc/audit/rules.d/
  6. ExecStartPost=-/sbin/augenrules --load
  7. #ExecStartPost=-/sbin/auditctl -R /etc/audit/audit.rules
  8. ExecReload=/bin/kill -HUP $MAINPID
  9. # By default we don't clear the rules on exit. To enable this, uncomment
  10. # the next line after copying the file to /etc/systemd/system/auditd.service
  11. #ExecStopPost=/sbin/auditctl -R /etc/audit/audit-stop.rules
  12. [Install]
  13. WantedBy=multi-user.target

最佳答案

这已在 Red Hat Bugzilla #1026648 中进行了探索、讨论和解决(大部分)。和 Anisble Issue # 22171 (github)报告。

分析:

  • 使用 ansible service模块参数use=service强制执行 /sbin/service实用程序而不是 systemd 的聚集事实值(调用 /sbin/systemctl )像这样:
- service: name=auditd state=restarted use=service
- command: /sbin/service auditd restart

分析——根本原因:
 

  • This is an issue created by upstream packaging of auditd.service unit. It will not start/stop/restart when acted upon by systemctl, apparently by design.
  • It is further compounded by the Ansible service control function, which uses the preferred method identified when system facts are gathered and "ansible_service_mgr" returns "systemd". This is regardless of the actual module used to manage the service.unit.
  • RHEL dev team may fix if considered a problem in upcoming updates (ERRATA)
  • Ansible dev team has offered a workaround and (as of 2.2) updated the service module with the use parameter.

关于ansible:如何在centos 7上重新启动auditd服务得到关于依赖的错误,我们在Stack Overflow上找到一个类似的问题: centos7 - ansible: how to restart auditd service on centos 7 get error about dependency - Stack Overflow

https://stackoverflow.com/questions/41053331/

简单来说就是auditd开发者觉着auditd是系统底层记录日志的服务,不应由管理员重启或停止其服务。

解决方法:

1、使用service auditd restart可以绕过systemctl重启auditd服务。

2、修改systemd服务配置文件/usr/lib/systemd/system/auditd.service配置RefuseManualStop=No,执行systemctl deamon-reload。后可以使用systemctl restart auditd

在ansible-play里,1、可以使用command模块代替service模块,重启auditd服务。

- command: /sbin/service auditd restart

或者2、修改auditd.service配置文件,使systemctl可以管理auditd

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/860404
推荐阅读
相关标签
  

闽ICP备14008679号