当前位置: 首页 > news >正文

Ansible模块——Ansible的安装!

Ansible 安装

Ansible 有三种安装方式,源码安装发行版安装和 Python 安装

使用发行版安装或 Python 安装两种方式时,Ansible 的安装包有两个,区别如下:

  • • ansible-core:一种极简语言和运行时包,包含一组内置模块和插件。

  • • ansible:一个更大的“包含电池”的软件包,它添加了社区精选的 Ansible 集合选择,用于自动化各种设备。

在用源码或者 Python 安装 Ansible 时,默认不会安装 sshpass 软件包,该软件包用来给 Ansible 提供密码验证被控端,因此如果在执行 Ansible 的命令时需要输入 ssh 的密码,则需要该软件包,该软件包通过 dnf install -y sshpass

[root@ansible ansible]# ansible servera -m ping
servera | FAILED! => {"msg": "to use the 'ssh' connection type with passwords or pkcs11_provider, you must install the sshpass program"
}

本次安装使用 Rocky 8 Linux 系统。

源码安装

[root@ansible ~]# dnf install python3.12 python3.12-pip sshpass
[root@ansible ~]# tar xf ansible-2.16.3.tar.gz
[root@ansible ~]# cd ansible-2.16.3/
[root@ansible ansible-2.16.3]# python3 -m pip install -r ./requirements.txt
[root@ansible ansible-2.16.3]# python3 setup.py install

源码安装只能安装 Ansible-core

发行版安装

[root@ansible ~]# dnf install -y epel-release# 安装最简洁的 Ansible
[root@ansible ~]# dnf install ansible-core# 安装包含常用模块的 Ansible
[root@ansible ~]# dnf install ansible

Python 安装

# 安装 Python3 和 pip
[root@ansible ~]# dnf install python3.12 python3.12-pip sshpass# 安装 Ansible-core
[root@ansible ~]# python3.12 -m pip install ansible-core==2.16.3# 安装 Ansible
[root@ansible ~]# python3.12 -m pip install ansible

设置 Ansible 参数自动补全

[root@ansible ~]# python3 -m pip install argcomplete
[root@ansible ~]# activate-global-python-argcomplete --user

重新登录命令行加载一下环境变量就可以看到自动补全了。

快速配置并使用 Ansible

有一个被控节点,地址为 192.168.221.131,主机名为 servera

[root@ansible ~]# mkdir ansible
[root@ansible ~]# cd ansible
[root@ansible ansible]# sed -i 's/;inventory=.*/inventory\ =\ .\/inventory/' ansible.cfg
[root@ansible ansible]# cat <<-EOF > ansible.cfg
[defaults]
inventory      = ./inventory
ask_pass       = false
remote_user    =  root
log_path       = /var/log/ansible.log
host_key_checking = False
[privilege_escalation]
become = True
become_method = sudo
become_user = root
become_ask_pass = False
[ssh_connection]
ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no
EOF
[root@ansible ansible]# echo servera > inventory
[root@ansible ansible]# tail -n1 /etc/hosts
192.168.221.131 servera# 通过 ping 模块测试网络连通性
[root@ansible ansible]# ansible all -k -m ping
SSH password:
servera | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"},"changed": false,"ping": "pong"
}

相关文章:

  • 每日C++ 5.28dddd
  • 微信小程序返回上一页监听
  • 【产品小白】京东外卖为何未独立成 APP
  • ToolsSet之:Json格式化
  • 【深度学习-pytorch篇】1. Pytorch矩阵操作与DataSet创建
  • Python后端开发实战:从0到1搭建高可用API服务
  • Linux命令行命令自动补全
  • vs中添加三方库的流程
  • webpack打包基本配置
  • GUI 编程——python
  • 干货|VR全景是什么?
  • 同源“平滑思想”的问题解法:正则化与拉普拉斯平滑
  • hi3516cv610分配多个 vb pool及查看vb信息
  • Linux的SHELL脚本基础
  • 在qt中使用c++实现与Twincat3 PLC变量通信
  • Kubernetes Dashboard 安装部署、访问与管理实战实验
  • VScode单双引号、分号格式
  • 【深度学习-pytorch篇】4. 正则化方法(Regularization Techniques)
  • ParakeetTDT0.6BV2,语音识别ASR,极速转录, 高精度英文转录,标点支持(附整合包)
  • 常用算法模板函数(Python)
  • 网页设计基础开题报告及网页流程图/做抖音seo排名软件是否合法
  • 中山网站制作网页/如何自己做网络推广
  • 郑州个人做网站/西地那非片能延时多久每次吃多少
  • ctb自己做网站/黑帽seo工具
  • 网站怎样做seo推广/站长友情链接
  • 注册网站怎么做/百度推广客户端下载安装