由于权限被拒绝,剧本无法执行
Playbook failing execution due to permission denied
库存内容如下:
[osm]
osm_host ansible_port=22 ansible_host=10.20.20.11 ansible_user=ubuntu ansible_ssh_private_key_file=/path/to/key/key
这是剧本内容:
- hosts: osm
user: ubuntu
become: yes
tasks:
- name: Download the OSM installer
get_url: url=https://osm-download.etsi.org/ftp/osm-8.0-eight/install_osm.sh dest=/tmp/install_osm.sh
- name: Execute the OSM installer
shell: /tmp/install_osm.sh
当我 运行 ansible-playbook -i inventory play.yaml
时,出现以下错误:
PLAY [osm]
TASK [Gathering Facts]
********************************************************* ok: [osm_host]
TASK [Download the OSM installer]
********************************************** ok: [osm_host]
TASK [Execute the OSM installer]
*********************************************** fatal: [osm_host]: FAILED! => {"changed": true, "cmd": "/tmp/install_osm.sh", "delta":
"0:00:00.001919", "end": "2020-09-04 19:26:46.510381", "msg":
"non-zero return code", "rc": 126, "start": "2020-09-04
19:26:46.508462", "stderr": "/bin/sh: 1: /tmp/install_osm.sh:
Permission denied", "stderr_lines": ["/bin/sh: 1: /tmp/install_osm.sh:
Permission denied"], "stdout": "", "stdout_lines": []}
PLAY RECAP
********************************************************************* osm_host : ok=2 changed=0 unreachable=0
failed=1 skipped=0 rescued=0 ignored=0
我尝试对 become
子句使用 true
和 yes
,但没有任何改变。我错过了什么?
您必须确保 root 用户对新的 OSM 下载具有可执行权限。当你使用 become: yes 而没有 become_user 时,默认用户是 root
所以你需要确保root用户可以执行你的脚本。
像那样尝试 get_url:
- hosts: osm
user: ubuntu
become: yes
tasks:
- name: Download the OSM installer
get_url:
url: https://osm-download.etsi.org/ftp/osm-8.0-eight/install_osm.sh
dest: /tmp/install_osm.sh
mode: "0555"
- name: Execute the OSM installer
shell: /tmp/install_osm.sh
使用 get_url 模块的 mode 参数。
库存内容如下:
[osm]
osm_host ansible_port=22 ansible_host=10.20.20.11 ansible_user=ubuntu ansible_ssh_private_key_file=/path/to/key/key
这是剧本内容:
- hosts: osm
user: ubuntu
become: yes
tasks:
- name: Download the OSM installer
get_url: url=https://osm-download.etsi.org/ftp/osm-8.0-eight/install_osm.sh dest=/tmp/install_osm.sh
- name: Execute the OSM installer
shell: /tmp/install_osm.sh
当我 运行 ansible-playbook -i inventory play.yaml
时,出现以下错误:
PLAY [osm]
TASK [Gathering Facts] ********************************************************* ok: [osm_host]
TASK [Download the OSM installer] ********************************************** ok: [osm_host]
TASK [Execute the OSM installer] *********************************************** fatal: [osm_host]: FAILED! => {"changed": true, "cmd": "/tmp/install_osm.sh", "delta": "0:00:00.001919", "end": "2020-09-04 19:26:46.510381", "msg": "non-zero return code", "rc": 126, "start": "2020-09-04 19:26:46.508462", "stderr": "/bin/sh: 1: /tmp/install_osm.sh: Permission denied", "stderr_lines": ["/bin/sh: 1: /tmp/install_osm.sh: Permission denied"], "stdout": "", "stdout_lines": []}
PLAY RECAP ********************************************************************* osm_host : ok=2 changed=0 unreachable=0
failed=1 skipped=0 rescued=0 ignored=0
我尝试对 become
子句使用 true
和 yes
,但没有任何改变。我错过了什么?
您必须确保 root 用户对新的 OSM 下载具有可执行权限。当你使用 become: yes 而没有 become_user 时,默认用户是 root 所以你需要确保root用户可以执行你的脚本。
像那样尝试 get_url:
- hosts: osm
user: ubuntu
become: yes
tasks:
- name: Download the OSM installer
get_url:
url: https://osm-download.etsi.org/ftp/osm-8.0-eight/install_osm.sh
dest: /tmp/install_osm.sh
mode: "0555"
- name: Execute the OSM installer
shell: /tmp/install_osm.sh
使用 get_url 模块的 mode 参数。