二、ansible安装
ubuntu与centos(换源阿里云后直接安装)
centos需要epel.repo源:https://developer.aliyun.com/mirror/epel/
换源:https://developer.aliyun.com/mirror/
1 2 3 4 5 6 7
| root@k8s:/mydata/jenkins_home/secrets# ansible --version ansible 2.9.6 config file = /etc/ansible/ansible.cfg configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python3/dist-packages/ansible executable location = /usr/bin/ansible python version = 3.8.10 (default, Mar 18 2025, 20:04:55) [GCC 9.4.0]
|
centos可用博主多年以前写的脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| #!/bin/bash
welcome() { cat <<EOF 1.需要用到的命令awk/ansible --version 2.需要用到的循环for/if 安装ansible需要epel源 EOF } start() { epel_check=`ls /etc/yum.repos.d/epel.repo` version=`ansible --version |awk -F'[ .]+' 'NR==1{print $1}'` } [ -f ${epel_check} ] && echo "已存在epel源" || wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo if [ "${epel_check}" = "epel.repo" -a "${version}" = "ansible" ]; then echo "ansible已安装" else yum install -y ansible [ "$?" = "0" ] && echo "安装成功" || echo "安装失败请检查" fi } main() { welcome start } main
|