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

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"
}
http://www.xdnf.cn/news/9571.html

相关文章:

  • k8s Headless Service
  • 懒人云电脑方案:飞牛NAS远程唤醒 + 节点小宝一键唤醒、远程控制Windows!
  • day10机器学习的全流程
  • 嵌入式通用集成电路卡市场潜力报告:物联网浪潮下的机遇与挑战剖析
  • 政务小程序TOP3交互设计分析:便民服务的隐藏心机
  • C语言 文件操作(2)
  • 实验三 企业网络搭建及应用
  • 基于线结构光模型的工件孔洞检查
  • 第五章 面向对象(进阶)
  • CC工具箱2.0.6更新_免费_150+工具
  • 智能外呼机器人——客户筛选
  • 桃黑黑反斗战
  • Doris主键模型使用异步物化视图
  • Linux——数据链路层
  • 仿DeepSeek AI问答系统完整版(带RAG本地知识库+联网搜索+深度思考) +springboot+vue3
  • JS手写代码篇---Pomise.race
  • 2024 CKA模拟系统制作 | Step-By-Step | 11、题目搭建-查看可用节点数量
  • Mysql基础增删改查语句
  • XCTF-web-file_include
  • 智慧财务系统:企业数字化转型的核心引擎
  • [yolov11改进系列]基于yolov11引入混合标准卷积与深度可分离卷积GSConv用于轻量化网络的python源码+训练源码
  • Android获取设备信息
  • github actions入门指南
  • .NET 9正式发布,亮点是.NET Aspire和AI
  • Linux `vi/vim` 编辑器深度解析与高阶应用指南
  • Golang | 搜索哨兵-对接分布式gRPC服务
  • vue修改配置文件.env.development不生效
  • 2025-05-28 学习记录--Python-文件
  • 对象检测新纪元:D-FINE 模型超越 YOLO,带来更精准的实时检测!
  • 6.2 Q1|哈尔滨医科大学GBD发文 | 1990 年至 2019 年颗粒物污染导致的中风全球趋势和负担