Ansible(1) Centos7安装Ansible
角色 | IP | 系统 |
---|---|---|
ansible server | 120.53.13.240 | Centos7.6 |
client | 123.207.166.69 | Centos7.6 |
确保Python的版本在2.6以上,如果是Centos7的话自带Python2.7.5
可以使用pthone -V 进行查看。
1、关闭防火墙
[root@ansible ~]# systemctl stop firewalld
[root@ansible ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
2、ansabile安装
[root@ansible ~]# yum install epel-release -y
[root@ansible ~]# yum install ansible -y
3、配置秘钥
[root@ansible ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:+dF9Y6Qkmxdyjm8LlAEy40KGaIAIj7YmDfzxfa03I5I root@ansible
The key's randomart image is:
+---[RSA 2048]----+
|B . .o + . |
|+= .o . + . |
|+o.. . . + + . |
|.oo o o ...%.+ |
|.o.. . .S..B.+.o.|
|o o.o.o ...|
| E o.= o |
| . o = . |
| . |
+----[SHA256]-----+
[root@ansible ~]#
4、将秘钥上传至客户端
[root@ansible ~]# scp /root/.ssh/id_rsa.pub root@123.207.166.69:/root/.ssh/authorized_keys
The authenticity of host '123.207.166.69 (123.207.166.69)' can't be established.
ECDSA key fingerprint is SHA256:+Pc5SdHeWlF7Wk1a+7zgdFww8MUMXys7W5xBxxVV0PI.
ECDSA key fingerprint is MD5:01:7a:de:00:77:33:2a:90:a7:e6:6f:21:01:b5:d3:06.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '123.207.166.69' (ECDSA) to the list of known hosts.
root@123.207.166.69's password:
id_rsa.pub 100% 394 78.3KB/s 00:00
5、配置ansible
[root@ansible ~]# vim /etc/ansible/ansible.cfg
remote_port = 22
private_key_file = /root/.ssh/id_rsa
Ansible配置文件/etc/ansible/ansible.cfg(一般保持默认)
[defaults]
# some basic default values...
#inventory = /etc/ansible/hosts #主机列表配置文件
#library = /usr/share/my_modules/ #库文件存放目录
#module_utils = /usr/share/my_module_utils/ #临时py命令文件存放在远程主机目录
#remote_tmp = ~/.ansible/tmp #本机的临时命令执行目录
#local_tmp = ~/.ansible/tmp
#plugin_filters_cfg = /etc/ansible/plugin_filters.yml
#forks = 5 #默认并发数量
#poll_interval = 15
#sudo_user = root #默认sudo用户
#ask_sudo_pass = True #每次执行ansible命令是否询问ssh密码
#ask_pass = True
#transport = smart
#remote_port = 22 #远程端口 与ssh保持一致
#module_lang = C
#module_set_locale = False #检查对应服务器的host_key,建议取消注释
#log_path = /var/log/ansible.log #日志文件建议开启
6、配置管理的机器
[root@ansible ~]# vim /etc/ansible/hosts
[clienthosts] ##最后添加
123.207.166.69
7、执行命令进行测试
[root@ansible ~]# ansible clienthosts -m command -a 'uptime'
123.207.166.69 | CHANGED | rc=0 >>17:06:48 up 10 days, 1:39, 2 users, load average: 0.08, 0.11, 0.07[root@ansible ~]# ansible clienthosts -m command -a 'uname -a'
123.207.166.69 | CHANGED | rc=0 >>
Linux VM_16_6_centos 3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 6 15:49:49 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
8、常用命令
ansible-doc -l #查看支持的模块
ansible-doc -s MODEL_NAME #查看模块用法
ansible命令应用基础
ansible <host-pattern> [options]
-f fork:启动并发 线程数
-m model_name:要使用的模块
-a args:特有的参数ansible all -m ping #查看client端是否正常ping通
ansible webserver -m setup #查看客户端信息
ansible webserver -m copy -a 'src=/root/git_test/code.txt dest=/root/test' #copy文件到client端
ansible webserver -m user -a "name=test state=present" #创建test用户
ansible webserver -m user -a "name=test state=absent" #删除test用户
ansible webserver -m yum -a 'name=epel-relese state=latest' #yum安装
ansible webserver -m systemd -a 'name=httpd state=stopped enabled=no' #停止httpd服务
ansible webserver -m script -a '/tmp/test,sh' #运行脚本
ansible webserver -m command 'date' #查看时间
Ansible(1) Centos7安装Ansible相关推荐
- centos7安装ansible
Centos7安装ansible 一.安装ansible软件 1.安装yum源 rpm -Uvh http://mirrors.ustc.edu.cn/epel/epel-release-latest ...
- centos7安装ansible AWX17.1.0
wget -c https://github.com/ansible/awx/archive/17.1.0.tar.gz 需要docker docker-compose环境 Linux:~ # pip ...
- Ansible篇-CentOS7安装AWX详解
1 引言 网上很多教程,但是根据教程安装一直报错,唉,排错重重,赶紧记下笔记! 2 系统要求 至少4G内存 至少2 CPU 至少20G磁盘空间 可运行docker,k8s,openshift 3 环境 ...
- centos7离线安装ansible
centos7离线安装ansible: 1.通过在线的centos7将rpm包下载好了,上传到指定服务器. 下载官方repo,rpm -iUvh http://dl.Fedoraproject.org ...
- 阿里云ECS服务器 Centos7.2 使用 yum 安装 ansible 报错
#####################使用阿里云的ECS服务器Centos7.2系统安装ansible提示安装不上########### 原因 通过Yum安装最新发布版本 通过Yum安装RPMs适 ...
- CentOS7.9奶妈级教程安装Ansible AWX 17.1.0
AWX提供了基于web的用户界面.REST API和建立在Ansible之上的任务引擎.本教程将指导您在CentOS/RHEL 7的Docker容器中设置Ansible AWX的步骤. 请注意,这些说 ...
- centos 7使用tar包安装ansible
由于我的yum源没有ansible软件包,防止以后内网服务器也没有ansible的yum源,干脆一点,直接tar包安装!!!! 下载软件包 - # 1.python安装 # python2.7安装 [ ...
- 教你十分钟在Linux系统上快速装机并安装Ansible
PS:本教程建立在VMware软件上的使用上,Linux版本为centos7或者centos8都可以. 一.看发行版本 cat /etc/redhat-release 二.修改主机名 hostnam ...
- Ansible 源码安装
1.简介 ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet.cfengine.chef.func.fabric)的优点,实现了批量系统配置.批量程序部署. ...
最新文章
- ”拿来搞笑“的大学生活
- Spring scope解惑
- 这二维码鬼畜起来了,加颜色加插画还能加GIF
- Issue 140: Tweet
- fedora linux操作系统安装,Fedora-10 Linux操作系统的安装,Fedora Linux的安装锦集收藏,图文并茂详解...
- Oracle集合运算
- jpa之PagingAndSortingRepository带分页查询
- C提高_day03_两个辅助指针变量挖字符串(强化4)
- 鸿蒙系统打通iOS,库克真的做到了!正式官宣确认截胡鸿蒙OS系统:软硬件生态全打通...
- 关于Java的Object.clone()方法与对象的深浅拷贝,java面试题,java初级笔试题
- vue循环出来列表里面的列表点击click事件只对当前列表有效;
- python自动下载图片_python简易爬虫来实现自动图片下载
- 调用网站第三方接口实现短信发邮件
- 软件工程毕业设计要求
- 菜鸟第一次使用pycharm+mysql+django运行项目
- hcie lab 实验挂了怎么办?
- CSP-2022 游寄
- 你所不知道的那些阿里面试|原来我也可以从小白到年薪百万!
- 软件测试,软件测试练习题
- c语言求某年某月1日是星期几,蔡勒(Zeller)公式:根据日期推算是星期几