【问题标题】:Ansible privilege escalation prompt problemAnsible提权提示问题
【发布时间】:2020-02-11 23:58:19
【问题描述】:
---
- name: Transfer and execute a script.
  hosts: jumpbox
  remote_user: pppruser
  any_errors_fatal: true
  gather_facts: no
  become: true
  become_method: su
  become_user: splunk
  become_flags: '-s /bin/sh'
  tasks:
     - name: Transfer the script
       copy: src=test.sh dest=/home/splunk/ mode=0777
     - name: Execute the script
       command: sh /export/home/splunk/test.sh
[splunk@ansible playbooks]$ cat test.sh
#!/bin/bash
cat /etc/passwd > /tmp/test

使用上面的 main.yml 脚本并在 playbook 命令下面使用

$ansible-playbook /etc/ansible/playbooks/main.yml --extra-vars "host=jumpbox" --ask-become-pass 
SUDO password:
PLAY [Transfer and execute a script.] **********************************************************************************
TASK [Transfer the script] *********************************************************************************************
fatal: [192.168.1.20]: FAILED! => {"msg": "Timeout (12s) waiting for privilege escalation prompt: "}
NO MORE HOSTS LEFT *****************************************************************************************************
        to retry, use: --limit @/etc/ansible/playbooks/main.retry
PLAY RECAP *********************************************************************************************************
192.168.1.20               : ok=0    changed=0    unreachable=0    failed=1

它因错误而失败。我尝试了来自多个论坛的不同选项和不同建议。但没有任何效果。在目标服务器(192.168.1.20)上,我有 remote_user(pppruser)和服务帐户(splunk)。 pppruser 具有 splunk 的 sudo 权限。这是 pppruser 帐户的 sudo 列表

$sudo -l
User pppruser may run the following commands on this host:
    (root) /bin/su - splunk
$sudo su - splunk

谁能建议我在哪里需要更改配置才能以 splunk 用户身份运行我的 playbook 执行而不会出现问题。

【问题讨论】:

标签: ansible privileges escalation


【解决方案1】:

你可能想看看这个enter link description here

- name: Transfer and execute a script.
  hosts: jumpbox
  remote_user: pppruser
  any_errors_fatal: true
  gather_facts: no
  become: true
  become_user: splunk
  tasks:
     - name: Transfer the script
       copy: src=test.sh dest=/home/splunk/ mode=0777

     - name: Execute the script
       command: sh /export/home/splunk/test.sh

【讨论】:

  • 感谢您的建议。但是我能够通过更改我的目标服务器 sudoers 文件来解决问题。我会尽快发布我的答案。
【解决方案2】:

在我的目标服务器中添加以下 sudo 权限解决了这个问题。

pppruser ALL=(root) /bin/su - splunk pppruser ALL=(splunk) /bin/sh

【讨论】:

    猜你喜欢
    • 2015-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-04
    • 1970-01-01
    • 2014-04-02
    • 2014-03-18
    相关资源
    最近更新 更多