我有以下ansible剧本:
- hosts: all
gather_facts: false
sudo: true
tasks:
- name: Pull sources from the repository.
git: repo=https://github.com/mongodb-labs/mongo-connector.git dest=/srv/checkout/mongo-connector
- hosts: all
sudo: true
tasks:
- name: copy local config.json to remote if exists
local_action: stat path="./config.json"
register: file
ignore_errors: True
- name: copy file if it exists
copy: src=./config.json dest=/srv/checkout/mongo-connector/config.json force=yes
when: file.stat.exists
- hosts: all
sudo: true
tasks:
- name: copy local install_mc.sh to remote if exists
local_action: stat path="./install_mc.sh"
register: file
ignore_errors: True
- name: copy installation scripts
copy: src=./install_mc.sh dest=/srv/checkout/mongo-connector/install_mc.sh mode=755
when: file.stat.exists
- name: Execute script
script: /srv/checkout/mongo-connector/install_mc.sh
在这里,我从github中提取存储库,然后将config.json复制到我克隆git存储库的文件夹中.之后我需要运行python setup.py install来安装软件包,然后在同一目录下运行python setup.py install_service.
我将两个安装命令放在一个shell文件install_mc.sh中,并将该文件复制到我克隆存储库的同一目录中.
git存储库克隆在/ srv / checkout / mongo-connector /中.
以下是目录布局:
vagrant@vagrant-ubuntu-trusty-64:/srv/checkout/mongo-connector$pwd
/srv/checkout/mongo-connector
vagrant@vagrant-ubuntu-trusty-64:/srv/checkout/mongo-connector$ls
CHANGELOG.rst config.json ez_setup.py install_mc.sh LICENSE mongo_connector README.rst scripts setup.cfg setup.py tests
但后来我使用vagrant运行ansible脚本我在执行install_mc.sh期间遇到了followin错误:
==> connector: TASK [Execute script] **********************************************************
==> connector: task path: /vagrant/provisioning/mc_playbook.yml:36
==> connector: fatal: [127.0.0.1]: FAILED! => {"changed": true, "failed": true, "rc": 2, "stderr": "chmod: cannot access ‘./setup.py’: No such file or directory\npython: can't open file './setup.py': [Errno 2] No such file or directory\npython: can't open file './setup.py': [Errno 2] No such file or directory\n", "stdout": "", "stdout_lines": []}
==> connector:
==> connector: NO MORE HOSTS LEFT *************************************************************
==> connector: to retry, use: --limit @mc_playbook.retry
==> connector:
==> connector: PLAY RECAP *********************************************************************
==> connector: 127.0.0.1 : ok=10 changed=4 unreachable=0 failed=1
install_mc.sh的内容是:
#!/usr/bin/env bash
chmod +x ./setup.py
python ./setup.py install
python ./setup.py install_service
我该如何纠正这个问题?
解决方法:
我认为问题在于您假设install_mc脚本是从您复制到的目录中执行的,但script
模块实际上是从本地计算机读取的,并在远程节点的主目录中执行该脚本.
The script module takes the script name followed by a list of space-delimited arguments. The local script at path will be transferred to the remote node and then executed. The given script will be processed through the shell environment on the remote node. This module does not require python on the remote system, much like the raw module.
正如DeHaan后来建议的那样,使用command
模块运行两个setup.py命令可能会更好.那个允许你指定一个目录(使用chdir选项).
chmod可能是不必要的,因为1)你使用python二进制文件调用脚本,2)mongo维护者可能在他们的git存储库中建立了适当的权限.
原文地址:https://codeday.me/bug/20190628/1312477.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。