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

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.lryc.cn/news/2393831.html

相关文章:

  • 差分S参数-信号与电源完整性分析
  • ​扣子Coze飞书多维表插件-查询数据
  • 计算机模拟生物/化学反应有哪些软件?
  • PostIn V1.1.2版本发布,新增接口评审功能,提升接口质量与合理性
  • MySQL数据归档利器:pt-archiver原理剖析与实战指南
  • 【论文阅读】User Diverse Preference Modeling by Multimodal Attentive Metric Learning
  • Catch That Cow POJ - 3278
  • 【计算机网络】传输层TCP协议——协议段格式、三次握手四次挥手、超时重传、滑动窗口、流量控制、
  • 文件服务端加密—minio配置https
  • 界面开发框架DevExpress XAF实践:集成.NET Aspire后如何实现自定义遥测?
  • 多卡训练核心技术详解
  • 深度学习全面掌握指南
  • magic-api配置Git插件教程
  • 算法打卡第11天
  • 【决策分析】基于Excel的多变量敏感性分析解决方案
  • php:5.6-apache Docker镜像中安装 gd mysqli 库 【亲测可用】
  • 小程序跳转H5或者其他小程序
  • 【AI赋能,视界升级】智微智能S134 AI OPS,重构智慧大屏未来
  • 外网访问可视化工具 Grafana (Linux版本)
  • ass字幕嵌入mp4带偏移
  • WPF响应式UI的基础:INotifyPropertyChanged
  • JavaScript字符串方法全面指南:从基础到高级应用
  • 浅谈 JavaScript 性能优化
  • React从基础入门到高级实战:React 生态与工具 - 构建与部署
  • Kafka性能调优三剑客:深度解析buffer_memory、linger_ms和batch_size
  • 5分钟学会网络服务搭建,飞凌i.MX9352 + Linux 6.1实战示例
  • 网络安全-等级保护(等保) 3-2-2 GB/T 28449-2019 第7章 现场测评活动/第8章 报告编制活动
  • 74道TypeScript高频题整理(附答案背诵版)
  • PostgreSQL 临时表空间
  • N2语法 状態