ansible 批量安装yum包

摘要:
1.首先,安装ansibleyumm_installingable 2.修改ansible2参数,以防止在ssh为past_key_checking=False/host_key_checking=False/g'/etc/enable/enable时第一次判断为yes或nose i的/#host。cfg3.创建一个新的工作目录并编写一个hosts文件来配置hosts[root@192et]#猫

1、首先安装一下ansible

yum install ansible

2、修改一下ansible的参数以防ssh过去的时候需要首次判断yes  或者no 

sed -i 's/#host_key_checking = False/host_key_checking = False/g' /etc/ansible/ansible.cfg

3、新建一个工作目录,写一个hosts文件 用来配置hosts

[root@192 et]# cat hosts
[own_host]
web.ansible.bd.com

4、新建一个screen.yml文件,先比如安装一个screen,内容如下

- name: Install screen
  hosts: own_host
  tasks:
    - name: start install screen
      yum:
        name: screen
        state: installed

5、执行安装之前要做好ssh免密

ssh-keygen -t rsa
ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.0.100
[root@web ~]# ssh-keygen -t rsa
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:HC81CyaFnd4u2uxEhIg6CEISxw+XN/t4hP1vxfkbohY root@web.ansible.bd.com
The key's randomart image is:
+---[RSA 2048]----+
|o+.  . o..       |
|o.o.o.+oo        |
|o .+..o*=.o      |
|+.  . o=+=.o     |
|+      +Soo  . . |
| .    ..+.oE  +  |
|       =.. ..o o |
|      ..o  .+ . o|
|       .. .o   ..|
+----[SHA256]-----+
[root@web ~]#

[root@web ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.0.100 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" The authenticity of host '192.168.0.100 (192.168.0.100)' can't be established. ECDSA key fingerprint is SHA256:bqCO0nWIDL1xZsor1O5E819ZLoV2aE+TDOmiKNBM+sQ. ECDSA key fingerprint is MD5:21:18:a5:32:7f:9e:0e:48:41:d7:86:21:2a:36:8a:ee. Are you sure you want to continue connecting (yes/no)? yes /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@192.168.0.100's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh '192.168.0.100'" and check to make sure that only the key(s) you wanted were added. [root@web ~]#


6、执行批量安装

ansible-playbook -i /opt/et/hosts /opt/et/screen.yml
[root@web ~]# ansible-playbook -i /opt/et/hosts /opt/et/screen.yml

PLAY [Install screen] *********************************************************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************************************************************
ok: [web.ansible.bd.com]

TASK [start install screen] ***************************************************************************************************************************************************************
changed: [web.ansible.bd.com]

PLAY RECAP ********************************************************************************************************************************************************************************
web.ansible.bd.com         : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

[root@web ~]#

免责声明:文章转载自《ansible 批量安装yum包》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Dice LossNodeRED订阅MQTT主题并调试数据下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

centos7 安装图行界面及卸载

1、在终端上输入命令 $sudo yum groupinstall "GNOME Desktop" "Graphical Administration Tools" $sudo ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target  //修改运行级别 重...

git 配置多个SSH-Key

   我们在日常工作中会遇到公司有个gitlab,还有些自己的一些项目放在github上。这样就导致我们要配置不同的ssh-key对应不同的环境。下面我们来看看具体的操作: 1,生成一个公司用的SSH-Key      $ ssh-keygen -t rsa -C "youremail@yourcompany.com” -f ~/.ssh/id-rsa 在...

buildroot 添加ssh,以及使用stftp 服务

上一篇水了一下关于buildroot的基本操作,这一章水一下开启SSH服务以及配置sftp服务,以及静态IP的设置。 配置:   make menuconfig   Target packages  ---> Networking applications  --->      把这个服务加上去。   system configuration...

ssh密钥登录

方法一: 使用下例中ssky-keygen和ssh-copy-id,仅需通过3个步骤的简单设置而无需输入密码就能登录远程Linux主机。 ssh-keygen 创建公钥和密钥。 ssh-copy-id 把本地主机的公钥复制到远程主机的authorized_keys文件上。ssh-copy-id 也会给远程主机的用户主目录(home)和~/.ssh, 和~/...

部署经验Docker

从Docker 到Jenkins 到Ansible的部署经验 https://www.cnblogs.com/itdragon/p/10011816.html 工作中,除了开发功能,还负责系统的部署工作。我从频繁的部署工作中,逐渐找到了一些偷懒的方法。从传统的Java -jar命令启动服务,到通过Docker 容器构建部署服务,再后来通过自动化部署工具Je...

SSH认证原理和批量分发管理

SSH密码认证原理 几点说明: 1.服务端/etc/ssh目录下有三对公钥私钥: [root@m01 ssh]# ls moduli ssh_config sshd_config ssh_host_dsa_key ssh_host_dsa_key.pub ssh_host_key ssh_host_key.pub ssh_host_rsa...