【问题标题】:Unable to escalate privileges for a task in ansible even after using become即使在使用成为后也无法升级 ansible 中任务的权限
【发布时间】:2018-01-10 07:54:04
【问题描述】:

我正在尝试使用 ansible 自动化一个场景。

- name: Copy NRPE Upgrade script
  template: src=nagiosclient.sh.j2 dest=/var/tmp/nagiosclient.sh

- name: Add Execute  permissions of the script
  file: dest=/var/tmp/nagiosclient.sh mode=a+x

- name: Execute the NRPE script
  script: /var/tmp/nagiosclient.sh
  become: true
  tags: test

这是我的剧本的摘录。此 playbooks 成功运行复制并添加执行权限任务。

但是当我尝试运行时,执行失败。

由于 ansible 试图以“gparasha”用户身份登录,因此该用户无法使用此路径 /var/tmp。

但即使我在上面完成的任务中添加了“成为:true”, 甚至在 ansible playbook 任务中使用 --become 之后, 即“ansible-playbook -i hosts tltd.yml --become --tags test”

我收到权限被拒绝错误..

谁能建议这里有什么问题以及如何纠正它?

gparasha-macOS:TLTD gparasha$ ansible-playbook -i hosts tltd.yml --become --tags test

PLAY [Run tasks on Author] **************************************************************************************************************************************************************

TASK [Gathering Facts] ******************************************************************************************************************************************************************
ok: [13.229.22.58]
fatal: [34.198.174.78]: UNREACHABLE! => {"changed": false, "msg": "Authentication failure.", "unreachable": true}

TASK [author : Execute the NRPE script] *************************************************************************************************************************************************
fatal: [13.229.22.58]: FAILED! => {"changed": false, "failed": true, "msg": "Could not find or access '/var/tmp/nagiosclient.sh'"}
 [WARNING]: Could not create retry file '/opt/ansible/TLTD/tltd.retry'.         [Errno 13] Permission denied: u'/opt/ansible/TLTD/tltd.retry'


PLAY RECAP ******************************************************************************************************************************************************************************
13.229.22.58               : ok=1    changed=0    unreachable=0    failed=1   
34.198.174.78              : ok=0    changed=0    unreachable=1    failed=0   

【问题讨论】:

    标签: ansible ansible-2.x


    【解决方案1】:

    使用与否无关紧要,因为脚本模块从控制机器读取脚本文件,将其传输到目标并在那里执行(在您的情况下具有成为权限)。

    错误来自控制机器上/var/tmp/nagiosclient.sh处的脚本不存在。

    如果你想在目标上执行它,你应该使用shell模块并运行/var/tmp/nagiosclient.sh


    此外,权限被拒绝问题是完全无关的,它是一个无法创建重试文件的警告;也在控制机器上。

    【讨论】:

    • 如果你检查上面的行,脚本已经复制到上面的任务中
    • 没关系,因为script 模块就像我描述的那样工作。评论前请阅读。
    • 感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-09
    • 1970-01-01
    • 2020-01-04
    • 2016-06-07
    • 1970-01-01
    • 2020-12-07
    • 1970-01-01
    相关资源
    最近更新 更多