即使在使用 become 之后也无法提升 ansible 中任务的权限
Unable to escalate privileges for a task in ansible even after using become
我正在尝试使用 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
这是我的剧本的节选。此剧本成功 运行 复制和添加执行权限任务。
但是当我尝试 运行 时,执行失败。
因为 ansible 正在尝试以 'gparasha' 用户身份登录,所以此路径 /var/tmp 对该用户不可用,正如预期的那样。
但是即使我像上面那样在任务中添加 "become: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
不管你是否使用become,因为脚本模块从控制机器读取脚本文件,将其传输到目标并在那里执行(在你的情况下具有成为特权)。
错误是由于脚本在控制机器/var/tmp/nagiosclient.sh
不存在。
如果你想在目标上执行它,你应该使用 shell
模块和 运行 /var/tmp/nagiosclient.sh
.
此外,permission denied问题完全无关,是无法创建重试文件的警告;也在控制机上。
我正在尝试使用 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
这是我的剧本的节选。此剧本成功 运行 复制和添加执行权限任务。
但是当我尝试 运行 时,执行失败。
因为 ansible 正在尝试以 'gparasha' 用户身份登录,所以此路径 /var/tmp 对该用户不可用,正如预期的那样。
但是即使我像上面那样在任务中添加 "become: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
不管你是否使用become,因为脚本模块从控制机器读取脚本文件,将其传输到目标并在那里执行(在你的情况下具有成为特权)。
错误是由于脚本在控制机器/var/tmp/nagiosclient.sh
不存在。
如果你想在目标上执行它,你应该使用 shell
模块和 运行 /var/tmp/nagiosclient.sh
.
此外,permission denied问题完全无关,是无法创建重试文件的警告;也在控制机上。