-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<fix>[conf]: Isolating ansible with python venv #1347
Open
MatheMatrix
wants to merge
2
commits into
zstackio:master
Choose a base branch
from
MatheMatrix:test-feature1/test1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,60 @@ elif [ $tool = 'zstack-ctl' ]; then | |
chmod +x /usr/bin/zstack-ctl | ||
python $CTL_VIRENV_PATH/lib/python2.7/site-packages/zstackctl/generate_zstackctl_bash_completion.py | ||
|
||
elif [ $tool = 'zstack-sys' ]; then | ||
SYS_VIRENV_PATH=/var/lib/zstack/virtualenv/zstacksys | ||
NEED_INSTALL=false | ||
if [ -d $SYS_VIRENV_PATH ]; then | ||
. $SYS_VIRENV_PATH/bin/activate | ||
if ! ansible --version | grep -q 'core 2.11.12.3'; then | ||
deactivate | ||
NEED_INSTALL=true | ||
fi | ||
else | ||
NEED_INSTALL=true | ||
fi | ||
if $NEED_INSTALL; then | ||
rm -rf $SYS_VIRENV_PATH && virtualenv $SYS_VIRENV_PATH --python=python2.7 || exit 1 | ||
. $SYS_VIRENV_PATH/bin/activate | ||
cd $cwd | ||
pip install -i $pypi_path --trusted-host localhost --ignore-installed setuptools==39.2.0 || exit 1 | ||
pip install -i $pypi_path --trusted-host localhost --ignore-installed ansible==4.10.0 || exit 1 | ||
|
||
cat > /usr/bin/ansible << EOF | ||
#! /bin/sh | ||
VIRTUAL_ENV=/var/lib/zstack/virtualenv/zstacksys | ||
if [ ! -d $VIRTUAL_ENV ]; then | ||
echo "Need to install zstacksys before using it" | ||
exit 1 | ||
fi | ||
|
||
LANG=en_US.UTF-8 | ||
LC_ALL=en_US.utf8 | ||
export LANG LC_ALL | ||
. ${VIRTUAL_ENV}/bin/activate | ||
|
||
ansible \$@ | ||
EOF | ||
chmod +x /usr/bin/ansible | ||
|
||
cat > /usr/bin/ansible-playbook << EOF | ||
#! /bin/sh | ||
VIRTUAL_ENV=/var/lib/zstack/virtualenv/zstacksys | ||
if [ ! -d $VIRTUAL_ENV ]; then | ||
echo "Need to install zstacksys before using it" | ||
exit 1 | ||
fi | ||
|
||
LANG=en_US.UTF-8 | ||
LC_ALL=en_US.utf8 | ||
export LANG LC_ALL | ||
. ${VIRTUAL_ENV}/bin/activate | ||
|
||
ansible-playbook \$@ | ||
EOF | ||
chmod +x /usr/bin/ansible-playbook | ||
fi | ||
Comment on lines
+85
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在安装 Ansible 时,脚本直接写入 |
||
|
||
elif [ $tool = 'zstack-dashboard' ]; then | ||
UI_VIRENV_PATH=/var/lib/zstack/virtualenv/zstack-dashboard | ||
[ ! -z $force ] && rm -rf $UI_VIRENV_PATH | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
脚本使用
rm -rf
来删除现有的虚拟环境,这是一个破坏性操作,如果路径中包含错误或变量未设置,可能会非常危险。建议在执行此操作之前添加更多的检查,以确保路径是正确的,并且变量已经设置。脚本使用了
virtualenv --python=python2.7
,这表明它依赖于 Python 2.7。由于 Python 2.7 已经达到生命周期的终点,这可能是一个潜在的问题。如果可能,建议将脚本迁移到 Python 3,以确保长期的兼容性和安全性。There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除之前检查什么呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MatheMatrix 在执行删除操作之前,应该检查
SYS_VIRENV_PATH
变量确实已经被设置,并且不是指向根目录(/
)或用户的主目录(~
)。这可以通过添加一些条件语句来实现,例如:这样可以防止脚本在变量为空或指向关键系统目录时执行危险的删除操作。