Linux | Ansible

本文介绍了Ansible的安装、版本查看、定义组、Command和Shell的测试,以及Group、User、复制和File模块的使用,是进行Linux系统自动化运维的基础教程。
摘要由CSDN通过智能技术生成

目录

安装Ansible

查看Ansible版本

定义Ansible组

测试Ansible Command&shell

Group 模块

User 模块

复制模块(copy/fetch)

File模块

References


Ansible是一种自动化的运维工具,基于Python开发,它集合了众多运维工具(比如puppet、chef、func等)的优点,能够实现批量操作。但其实Ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是Ansible所运行的模块,Ansible只是提供一种框架。

 

安装Ansible

yum install epel-release
yum repolist

# 若安装失败 则依次安装依赖 
yum install -y ansible

查看Ansible版本

 ansible --version

ansible 2.9.10
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Apr  2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

定义Ansible组

修改 /etc/ansible/hosts 文件中内容 ,添加组,如下:

vi /etc/ansible/hosts
#  接下来定义Ansible模块

#  ansible_ssh_port 连接目标远程主机的端口
#  ansible_ssh_user 连接目标远程主机默认用户
#  ansible_ssh_pass 连接目标远程主机默认用户密码

#  定义组 - bdp

[bdp]
192.168.254.121 ansible_ssh_port=22 ansible_ssh_user=root  ansible_ssh_pass='gis@pwd'
192.168.254.122 ansible_ssh_port=22 ansible_ssh_user=root  ansible_ssh_pass='gis@pwd'
192.168.254.123 ansible_ssh_port=22 ansible_ssh_user=root  ansible_ssh_pass='gis@pwd'
192.168.254.124 ansible_ssh_port=22 ansible_ssh_user=root  ansible_ssh_pass='gis@pwd'
192.168.254.125 ansible_ssh_port=22 ansible_ssh_user=root  ansible_ssh_pass='gis@pwd'
192.168.254.126 ansible_ssh_port=22 ansible_ssh_user=root  ansible_ssh_pass='gis@pwd'
# 修改该文件中 host_key_checking = False  (避免SSH_KEY问题)

vi /etc/ansible/ansible.cfg

测试Ansible Command&shell

ansible bdp -m command -a "free -m"
ansible bdp -m command -a "cat /etc/sysconfig/network-scripts/ifcfg-ens33"


ansible bdp -m shell  -a "cat /etc/sysconfig/network-scripts/ifcfg-ens33"

接下来学习下基于Ansible批量创建用户与用户组

Group 模块

Group 模块主要用来添加或者删除组。

ansible-doc -s group

- name: Add or remove groups
  group:
      gid:                   # Optional `GID' to set for the group.
      local:                 # Forces the use of "l
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值