【问题标题】:Playbook failing execution due to permission denied由于权限被拒绝,Playbook 无法执行
【发布时间】:2020-09-08 00:39:22
【问题描述】:

这是库存内容:

[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 时,我收到以下错误:

播放 [osm]


TASK [收集事实] ****************************************************** ******* 好的:[osm_host]

任务 [下载 OSM 安装程序] ************************************************ 好的:[osm_host ]

TASK [执行 OSM 安装程序] *********************************************** 致命的: [ osm_host]:失败! => {“更改”:true,“cmd”:“/tmp/install_osm.sh”,“delta”: “0:00:00.001919”,“结束”:“2020-09-04 19:26:46.510381”,“味精”: “非零返回码”,“rc”:126,“start”:“2020-09-04 19:26:46.508462", "stderr": "/bin/sh: 1: /tmp/install_osm.sh: 权限被拒绝”,“stderr_lines”:[“/bin/sh:1:/tmp/install_osm.sh: 权限被拒绝"], "stdout": "", "stdout_lines": []}

播放回顾 ****************************************************** ******************* osm_host : ok=2 已更改=0 无法访问=0
失败=1 跳过=0 救出=0 忽略=0

我尝试将trueyes 用于become 子句,但没有任何改变。我错过了什么?

【问题讨论】:

    标签: ansible ansible-inventory


    【解决方案1】:

    您必须确保 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 参数。

    【讨论】:

    • 是的。由于我是 Ansible 的新手,我只是忘记了我应该设置要执行的文件权限。我在想这应该是我的 Ansible 文件中的一个问题。 =] 谢谢。顺便说一句,OSM 脚本需要不同于 root 的用户,所以,我删除了become: yes。 ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 1970-01-01
    • 1970-01-01
    • 2019-11-17
    相关资源
    最近更新 更多