首页 > 其他分享 >Ansible安装及简单使用

Ansible安装及简单使用

时间:2023-01-05 09:45:48浏览次数:58  
标签:doc cdh pc Ansible 模块 简单 root 安装 ansible

一、配置免密互通

  参考地址:https://www.cnblogs.com/qq1035807396/p/16998602.html

二、开始安装Ansible

1、添加repo

yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

2、yum安装ansible

yum install ansible -y

3、查看安装信息

rpm -qa ansible

4、添加主机清单

vim /etc/ansible/hosts
[pc_cdh]
master.cdh
slave1.cdh
slave2.cdh
slave3.cdh

5、查看当前ansible都支持哪些模块

ansible-doc -l

6、查看某个模块有哪些参数可以使用

ansible-doc -s 模块名

7、下面比较常用的几个模块:

ansible-doc -s copy
ansible-doc -s file
ansible-doc -s cron
ansible-doc -s group
ansible-doc -s user
ansible-doc -s yum
ansible-doc -s service
ansible-doc -s script
ansible-doc -s ping
ansible-doc -s command
ansible-doc -s raw
ansible-doc -s get_url
ansible-doc -s synchronize

三、模块介绍

1、copy模块

  目的:把主控端/root目录下的s.py文件拷贝到到指定节点上

ansible pc_cdh -m copy -a 'src=/root/s.py dest=/root/'

2、file模块

  目的:更改指定节点上的文件权限为755,属主和属组为root

ansible pc_cdh -m file -a "dest=/root/s.py mode=755 owner=root group=root"

3、cron模块

  目的:在指定节点上定义一个计划任务,每隔3分钟到主控端更新一次时间(先安装yum install ntpdate)

ansible pc_cdh -m cron -a 'name="custom job" minute=*/3 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate -d 12.12.104.220"'

4、group模块

  目的:在所有节点上创建一个组名为nolinux,gid为2014的组

ansible pc_cdh -m group -a 'gid=2014 name=nolinux'

5、user模块

  目的:在指定节点上创建一个用户名为nolinux,组为nolinux的用户

ansible pc_cdh -m user -a 'name=nolinux groups=nolinux state=present'

6、yum模块

  目的:在指定节点上安装 lrzsz 服务

ansible pc_cdh -m yum -a "state=present name=httpd"

7、service模块

  目的:启动指定节点上的 httpd服务,并让其开机自启动

ansible pc_cdh -m service -a 'name=httpd state=restarted enabled=yes'

8、script模块

  目的:在指定节点上执行/root/a.sh脚本(该脚本是在ansible控制节点上的)

ansible pc_cdh -m script -a '/root/a.sh'

9、ping模块

  目的:检查指定节点机器是否还能连通

ansible pc_cdh -m ping

10、command模块

  目的:在指定节点上运行hostname/pwd命令

ansible pc_cdh -m command -a 'hostname'
ansible pc_cdh -m command -a 'pwd'

11、synchronize模块

  目的:将主控方/root/testasible目录推送到指定节点目录下

ansible pc_cdh -m synchronize -a 'src=/root/testasible dest=/root/ compress=yes'

12、shell模块

  目的:在指定节点中执行shell命令

ansible pc_cdh -m shell -a 'uptime' -o
ansible pc_cdh -m shell -a 'date' -o
ansible pc_cdh -m shell -a 'echo "测试asible"' -o
ansible pc_cdh -m shell -a 'echo "测试asible" >> /root/a.sh' -o
ansible pc_cdh -m shell -a 'cat /root/a.sh' -o

 

标签:doc,cdh,pc,Ansible,模块,简单,root,安装,ansible
From: https://www.cnblogs.com/qq1035807396/p/17026617.html

相关文章

  • 使用Let's Encrypt 安装配置免费SSL 证书教程
    一、Let'sEncrypt简介Let'sEncrypt是一个由非营利性组织互联网安全研究小组(ISRG)提供的免费、自动化和开放的证书颁发机构(CA)。简单的说,借助Let'sEncrypt颁发的证......
  • centos7 安装 MySQL
    首先登陆MySQL官网。点击downloads。https://dev.mysql.com/downloads/这里我选择的是社区版。之后出现了很多选项。根据需求选择。因为我是centos,一开始准备使用y......
  • 使用Let's Encrypt 安装配置免费SSL 证书教程
    一、Let'sEncrypt简介Let'sEncrypt是一个由非营利性组织互联网安全研究小组(ISRG)提供的免费、自动化和开放的证书颁发机构(CA)。简单的说,借助Let'sEncrypt颁发的证......
  • MySQL安装
    一、官网下载mysql安装包https://www.mysql.com/安装其它版本windows安装包macbook安装二、安装mysqlwindows案例三、配置环境变量,启动mysql服务#......
  • Exchanger的简单使用
    Exchanger适用于超过一个线程之间数据交换  代码案例packagecom.java.test.exchanger;importorg.junit.Test;importjava.util.Random;importjava.util.con......
  • debian11命令行安装字体
    一、需要用到三条命令mkfontscale/mkfontdir/fc-cache这三条命令属于两个软件包mkfontscale/mkfontdir属于xfonts-utils包,fc-cache命令属于fontconfig包,这两个包都包含......
  • Mac OS 12.6 cocoapods 安装失败
    sudogeminstallcocoapods报错Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingcocoapods: ERROR:Failedtobuildgemnativee......
  • 中国移动魔百盒 安装当贝桌面
    中国移动魔百盒安装当贝桌面TableofContents一、起因二、经过三、效果ReferenceTable1.修改历史日期修订人备注2022-12-25崔嘉诚......
  • JDK的卸载和安装
    卸载我的电脑---属性---高级系统设置--环境变量--找到JAVAHOME,这里是放JAVA的地方,JDK直接删除文件夹环境变量删除JAVAHOME键值环境变量里PATH键里面,把JAVA相关......
  • ubunut安装flash
    1kxb@kxb:~$sudoapt-getinstallflashplugin-installer2[sudo]kxb的密码:3正在读取软件包列表...完成4正在分析软件包的依赖关系树5正在读取......