gpt4 book ai didi

python - 使用 ansible 从源代码安装 python 包

转载 作者:太空宇宙 更新时间:2023-11-03 10:59:29 24 4
gpt4 key购买 nike

我有以下 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 期间出现以下错误:

==> 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 存储库中建立了适当的权限。

关于python - 使用 ansible 从源代码安装 python 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35788037/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com