TDSQL 集群(10.3.14.1.0) 安装 ansible 报 No such file or directory 解决方法
作者:
dave
TDSQL 安装ansible报错,如下:
[dave@www.cndba.cn settings]# ls
ansible ansible.cfg install_ansible.py py_modules
[dave@www.cndba.cn settings]# ll
total 24
drwxr-xr-x. 4 root root 36 Mar 20 2019 ansible
-rw-r--r--. 1 root root 19332 Dec 30 2019 ansible.cfg
-rw-r--r--. 1 root root 663 Dec 30 2019 install_ansible.py
drwxr-xr-x. 2 root root 141 Jul 27 21:01 py_modules
[dave@www.cndba.cn settings]# ls
ansible ansible.cfg install_ansible.py py_modules
[dave@www.cndba.cn settings]# python install_ansible.py
Traceback (most recent call last):
File "install_ansible.py", line 11, in <module>
os.chdir(work_dir)
OSError: [Errno 2] No such file or directory: ''
[dave@www.cndba.cn settings]# cat install_ansible.py
#! /usr/bin/env python
# coding: utf-8
from py_modules import functions
import os
import shutil
import sys
os_version = functions.get_os_version()
work_dir = os.path.dirname(sys.argv[0])
os.chdir(work_dir)
msg_info = functions.colored('Ansible is install successful!', 'green')
if os_version == 1:
os.system('rpm -ivh --force ansible/centos6/*')
print msg_info
elif os_version == 2:
os.system('yum install -y openssl openssl-devel')
os.system('rpm -ivh --force ansible/centos7/*')
print msg_info
else:
print 'The OS type neither centos-6 nor centos-7, the program will be exit!'
shutil.copy('ansible.cfg', '/etc/ansible/ansible.cfg')
这里代码比较简单, 因为看到扩展名是py的所以加了python, 注意报错的11行获取地址的方式:sys.argv[0]。
所以我们这里直接执行,不加python。 如下:
[dave@www.cndba.cn settings]# pwd
/data/tdsql_full_install_ansible/settings
[dave@www.cndba.cn settings]# ls
ansible ansible.cfg install_ansible.py py_modules
[dave@www.cndba.cn settings]#
[dave@www.cndba.cn settings]# ./install_ansible.py
-bash: ./install_ansible.py: Permission denied
这里提示权限不足,附加权限,安装成功:
[dave@www.cndba.cn settings]# chmod a+x install_ansible.py
[dave@www.cndba.cn settings]# ./install_ansible.py
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Package 1:openssl-1.0.2k-19.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package openssl-devel.x86_64 1:1.0.2k-19.el7 will be installed
--> Processing Dependency: zlib-devel(x86-64) for package: 1:openssl-devel-1.0.2k-19.el7.x86_64
--> Processing Dependency: krb5-devel(x86-64) for package: 1:openssl-devel-1.0.2k-19.el7.x86_64
--> Running transaction check
……
[dave@www.cndba.cn settings]# ansible --version
ansible 2.5.1
config file = /data/tdsql_full_install_ansible/settings/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Mar 20 2020, 17:08:22) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
[dave@www.cndba.cn settings]#
版权声明:本文为博主原创文章,未经博主允许不得转载。