因为centos默认安装Python2,但是现在python2已经离我们而去,很多ansible module都更好的依赖于python3 ,所以我们经常会遇到ansible版本和python版本不兼容的问题
可能你遇到的报错有如下字眼,就说明遇到了缺少必要python库或者ansible 模块跟python版本不匹配问题
An exception occurred during task execution. To see the full
traceback, use -vvv. The error was: ImportError: No module named
kubernetes fatal: [k8s-master1]: FAILED! => {“changed”: false,
“error”: “No module named kubernetes”, “msg”: “Failed to import the
required Python library (openshift) on kubernetesM01’s Python
/usr/bin/python. Please read module documentation and install in the
appropriate location. If the required library is installed, but
Ansible is using the wrong Python interpreter, please consult the
documentation on ansible_python_interpreter”}
你可以选择在当前Python环境安装python依赖包解决问题,注意:这里的安装包是需要安装在被控制服务器(目标服务器)上的 ; 当然如果系统安装了python3也可以选择python3解释器
-
运行命令时添加
ansible localhost -m ping -e 'ansible_python_interpreter=/usr/bin/python3'
ansible-playbook sample-playbook.yml -e 'ansible_python_interpreter=/usr/bin/python3'
- 添加在ansible.cfg 中
localhost-py3 ansible_host=localhost ansible_connection=local ansible_python_interpreter=/usr/bin/python3
k8s-master1 ansible_host=192.100.30.164 ansible_ssh_pass=youpassword
- 添加在ansible-playbook剧本中
在tasks中声明
- hosts: test_server
tasks:
- name: install pip
apt:
name: python-pip
vars:
ansible_python_interpreter: /usr/bin/python
在剧本的范围内
- hosts: test_server
vars:
ansible_python_interpreter: /usr/bin/python
tasks:
- name: install pip
apt:
name: python-pip
ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。
主要包括:
(1)、连接插件connection plugins:负责和被监控端实现通信;
(2)、host inventory:指定操作的主机,是一个配置文件里面定义监控的主机;
(3)、各种模块核心模
这将安装ansible,python和terraform。
conda env创建--file依赖关系/bare-metal.yml
conda激活test_purl_obolibrary
conda停用
conda env删除-n test_purl_obolibrary
terraform -chdir = aws初始化
terraform -chdir = aws适用
terraform -chdir = aws显示
terraform -chdir = aws销毁
其实对python熟悉的人都可以自己用paramiko来写任务的分发系统,再结合gevent的协程就能实现异步的处理。
如果只想用工具的朋友可以使用一些工具,类似{puppet,saltstack,fabric,ansible,chef}等,其实这些工具的都是很好用的,不过于学习的成本,我建议大家使用ansible,这个模块封装的不错,功能也很齐全。
我们首先先安装ansible把
复制代码 代码如下:pip install ansible #其实我建议大家用ubuntu的系统,ubuntu的系统对开源的东西都支持的很好,而且apt的功能要比
1、如果遇到超时的问题
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: TimeoutError: Timer expired after 10 seconds
fatal: [100.69.149.62]: FAILED! => {“change...
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: If you are using a module and expect the file to exist on the remote, see the remote_src option
failed...
叨叨最近遇到的一些事以及见闻、思考。最近一直在折腾GreatSQL源码编译,以及整理ansible一键安装包相关的事。1. MySQL 8.0源码编译为了能在正式开源后,方便社区用户自行编...
问题:在使用ansible进行管理客户主机时,发现客户主机安装了多个版本的python,并且默认版本为3.0shell>>cat list192.168.2.9shell>>ansible all -m ping -i list --ask-pass -u test会报如下错误信息:192.168.2.9 | FAILED >> {"failed": true,...
【解决】kotlin第一次编译Android项目报Execution failed for task ':app:kaptDebugKotlin'.异常
Execution failed for task ':app:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction
BAD PASSWORD: The password is shorter than 8 characters
The password fails the dictionary check - it is too simplistic/systematic
passwd: Have exhausted maximum number of retries for service
\color...
# 指定 ansible 安装的modules
MODULE_PATH = "//home//production//env//devops//lib//python3.7//site-packages//ansible//modules"
def adhoc(host_list, task_list, remote_user='roo