gpt4 book ai didi

ubuntu - 如何使用交互式身份验证修复 systemctl?

转载 作者:行者123 更新时间:2023-12-04 18:37:24 32 4
gpt4 key购买 nike

我有一个配置 jenkins 的 ansible playbook,这个 playbook 作为 cloud-init-script 的一部分运行。
但是在 Jenkins 重启期间它失败了。谁能告诉我它要求什么交互式身份验证以及我应该如何解决这个问题?
版本:
ansible==2.9.6
Jenkins 版本:2.176.3
代码:

- name: Restart Jenkins
service:
name: jenkins
state: restarted

- name: Wait for Jenkins to start up
uri:
url: http://localhost:8080
user: "{{ jenkins_admin_username }}"
password: "{{ jenkins_admin_password }}"
force_basic_auth: true
status_code: 200
timeout: 5
register: jenkins_service_status
# Keep trying for 5 mins in 5 sec intervals
retries: 60
delay: 5
until: >
'status' in jenkins_service_status and
jenkins_service_status['status'] == 200
错误:
TASK [master : Restart Jenkins] ************************************************
task path: /opt/ihr-kopsfather/ansible-ihr-kopsfather/roles/master/tasks/restart_jenkins.yml:2
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root
<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /var/tmp/ansible-tmp-1597803601.9555757-44587295762829 `" && echo ansible-tmp-1597803601.9555757-44587295762829="` echo /var/tmp/ansible-tmp-1597803601.9555757-44587295762829 `" ) && sleep 0'
Using module file /usr/local/lib/python3.6/dist-packages/ansible/modules/system/systemd.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-19289oaudtdeg/tmprianjznn TO /var/tmp/ansible-tmp-1597803601.9555757-44587295762829/AnsiballZ_systemd.py
<127.0.0.1> EXEC /bin/sh -c 'setfacl -m u:jenkins:r-x /var/tmp/ansible-tmp-1597803601.9555757-44587295762829/ /var/tmp/ansible-tmp-1597803601.9555757-44587295762829/AnsiballZ_systemd.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'sudo -H -S -n -u jenkins /bin/sh -c '"'"'echo BECOME-SUCCESS-egbsbalzblxddrdjyadziewvzilaaacg ; /usr/bin/python3 /var/tmp/ansible-tmp-1597803601.9555757-44587295762829/AnsiballZ_systemd.py'"'"' && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /var/tmp/ansible-tmp-1597803601.9555757-44587295762829/ > /dev/null 2>&1 && sleep 0'
fatal: [127.0.0.1]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"daemon_reexec": false,
"daemon_reload": false,
"enabled": null,
"force": null,
"masked": null,
"name": "jenkins",
"no_block": false,
"scope": null,
"state": "restarted",
"user": null
}
},
"msg": "Unable to restart service jenkins: Failed to restart jenkins.service: Interactive authentication required.\nSee system logs and 'systemctl status jenkins.service' for details.\n"
systemctl 详细信息:
sudo systemctl status jenkins.service
● jenkins.service - LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; generated)
Active: active (exited) since Wed 2020-08-19 02:18:09 UTC; 8min ago
Docs: man:systemd-sysv-generator(8)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/jenkins.service

Aug 19 02:18:08 ip-10-23-11-7 systemd[1]: Starting LSB: Start Jenkins at boot time...
Aug 19 02:18:08 ip-10-23-11-7 jenkins[27353]: Correct java version found
Aug 19 02:18:08 ip-10-23-11-7 jenkins[27353]: * Starting Jenkins Automation Server jenkins
Aug 19 02:18:08 ip-10-23-11-7 su[27402]: Successful su for jenkins by root
Aug 19 02:18:08 ip-10-23-11-7 su[27402]: + ??? root:jenkins
Aug 19 02:18:08 ip-10-23-11-7 su[27402]: pam_unix(su:session): session opened for user jenkins by (uid=0)
Aug 19 02:18:08 ip-10-23-11-7 su[27402]: pam_unix(su:session): session closed for user jenkins
Aug 19 02:18:09 ip-10-23-11-7 jenkins[27353]: ...done.
Aug 19 02:18:09 ip-10-23-11-7 systemd[1]: Started LSB: Start Jenkins at boot time.

最佳答案

很可能您正在使用一个用户登录到不允许执行这些 systemctl 的目标。行动。所以你可能需要添加become: true完成您的任务(参见 documentation on become ):

- name: Restart Jenkins
become: true
service:
name: jenkins
state: restarted

关于ubuntu - 如何使用交互式身份验证修复 systemctl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63479193/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com