自动化运维工具-Ansible基础

什么是Ansible

Ansible是一个自动化统一配置管理工具

同类型软件对比

1.puppet 学习难,安装ruby环境难,没有远程执行功能

2.ansible 轻量级,大规模环境下只通过ssh会很慢,串行的

3.saltstack 一般选择salt会使用C/S结构的模式,salt-mastersalt-minion,并行的,大规模批量操作的情况下,会比Ansible速度快一些,底层使用的是zero-MQ消协队列

Ansible使用的是python2

saltstack即有python2也有python3

Ansible的功能及优点

1.远程执行

批量执行远程命令,可以对多台主机进行远程操作

2.配置管理

批量配置软件服务,可以进行自动化方式配置,服务的统一配置管理,和启停

3.事件驱动

通过Ansible的模块,对服务进行不同的事件驱动

比如:

1)修改配置后重启

2)只修改配置文件,不重启

3)修改配置文件后,重新加载

4)远程启停服务管理

4.管理公有云

通过API接口的方式管理公有云,不过这方面做的不如saltstack.

saltstack本身可以通过saltcloud管理各大云厂商的云平台。

5.二次开发

因为语法是Python,所以便于运维进行二次开发。

6.任务编排

可以通过playbook的方式来统一管理服务,并且可以使用一条命令,实现一套架构的部署

7.跨平台,跨系统

几乎不受到平台和系统的限制,比如安装apache和启动服务

在Ubuntu上安装apache服务名字叫apache2

在CentOS上安装apache服务名字叫httpd

在CentOS6上启动服务器使用命令:/etc/init.d/nginx start

在CentOS7上启动服务器使用命令:systemctl start nginx

Ansible的架构

Ansible的执行流程

1.Ansible读取playbook剧本,剧本中会记录对哪些主机执行哪些任务。

2.首先Ansible通过主机清单找到要执行的主机,然后调用具体的模块。

3.其次Ansible会通过连接插件连接对应的主机并推送对应的任务列表。

4.最后被管理的主机会将Ansible发送过来的任务解析为本地Shell命令执行。

安装Ansible

1.环境准备

主机名 wanIP lanIP 角色
m01 10.0.0.61 172.16.1.61 Ansible控制端
web01 10.0.0.7 172.16.1.7 Ansible被控端
web02 10.0.0.8 172.16.1.8 Ansible被控端

2.安装ansible

  1. [root@m01 ~]# yum install -y ansible

3.查看ansible模块及版本

  1. [root@m01 ~]# ansible --version
  2. ansible 2.8.4
  3. config file = /etc/ansible/ansible.cfg
  4. configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  5. ansible python module location = /usr/lib/python2.7/site-packages/ansible
  6. executable location = /usr/bin/ansible
  7. python version = 2.7.5 (default, Oct 30 2018, 23:45:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

4.ansible参数

  1. # ansible <host-pattern> [options]
  2. --version #ansible版本信息
  3. -v #显示详细信息
  4. -i #主机清单文件路径,默认是在/etc/ansible/hosts
  5. -m #使用的模块名称,默认使用command模块
  6. -a #使用的模块参数,模块的具体动作
  7. -k #提示输入ssh密码,而不使用基于ssh的密钥认证
  8. -C #模拟执行测试,但不会真的执行
  9. -T #执行命令的超时

5.ansible配置文件读取顺序

  1. [root@m01 ~]# vim /etc/ansible/ansible.cfg
  2. # nearly all parameters can be overridden in ansible-playbook
  3. # or with command line flags. ansible will read ANSIBLE_CONFIG,
  4. # ansible.cfg in the current working directory, .ansible.cfg in
  5. # the home directory or /etc/ansible/ansible.cfg, whichever it
  6. # finds first
  7. 1$ANSIBLE_CONFIG
  8. 2、./ansible.cfg
  9. 3、~/.ansible.cfg
  10. 4、/etc/ansible/ansible.cfg

ansible配置文件

  1. [root@m01 ~]# vim /etc/ansible/ansible.cfg
  2. #inventory = /etc/ansible/hosts #主机列表配置文件
  3. #library = /usr/share/my_modules/ #库文件存放目录
  4. #remote_tmp = ~/.ansible/tmp #临时py文件存放在远程主机目录
  5. #local_tmp = ~/.ansible/tmp #本机的临时执行目录
  6. #forks = 5 #默认并发数
  7. #sudo_user = root #默认sudo用户
  8. #ask_sudo_pass = True #每次执行是否询问sudo的ssh密码
  9. #ask_pass = True #每次执行是否询问ssh密码
  10. #remote_port = 22 #远程主机端口
  11. host_key_checking = False #跳过检查主机指纹
  12. log_path = /var/log/ansible.log #ansible日志
  13. #普通用户提权操作
  14. [privilege_escalation]
  15. #become=True
  16. #become_method=sudo
  17. #become_user=root
  18. #become_ask_pass=False

ansible Inventory(主机清单文件)

场景一:密码方式连接

  1. [root@m01 ~]# cat /etc/ansible/hosts
  2. #方式一、IP+端口+用户+密码
  3. [webs]
  4. 10.0.0.7 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1'
  5. 10.0.0.8 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass='1'
  6. #方式二、主机名+密码
  7. [webs]
  8. web0[1:2] ansible_ssh_pass='123456'
  9. #方式三、主机+密码
  10. [webs]web0[1:2]
  11. [webs:vars]
  12. ansible_ssh_pass='123456'
  13. 注意:方式二和方式三,都需要做hosts解析

场景二:密钥方式连接

  1. #创建密钥对
  2. [root@m01 ~]# ssh-keygen
  3. #推送公钥
  4. [root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.7
  5. [root@m01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@172.16.1.8
  6. #方式一:
  7. [web_group]
  8. 172.16.1.7
  9. 172.16.1.8
  10. #方式二:
  11. [webs]
  12. web01 ansible_ssh_host=172.16.1.7
  13. web02 ansible_ssh_host=172.16.1.8

场景三:主机组定义方式

  1. [web_group]
  2. web01 ansible_ssh_host=172.16.1.7
  3. web02 ansible_ssh_host=172.16.1.8
  4. [db_group]
  5. db01 ansible_ssh_host=172.16.1.51
  6. lb01 ansible_ssh_host=172.16.1.5
  7. [db_group:vars]
  8. ansible_ssh_pass='1'
  9. [nfs_group]
  10. nfs ansible_ssh_host=172.16.1.31
  11. [nfs_server:children]
  12. web_group
  13. nfs_group
  14. [lnmp:children]
  15. web_group
  16. db_group
  17. [root@m01 ~]# ansible 'all' --list-host
  18. hosts (5):
  19. nfs
  20. web01
  21. web02
  22. db01
  23. lb01
  24. [root@m01 ~]# ansible 'web_group' --list-host
  25. hosts (2):
  26. web01
  27. web02
  28. [root@m01 ~]# ansible 'db_group' --list-host
  29. hosts (2):
  30. db01
  31. lb01
  32. [root@m01 ~]# ansible 'lnmp' --list-host
  33. hosts (4):
  34. web01
  35. web02
  36. db01
  37. lb01

ad-hoc模式命令使用

ad-hoc

临时命令。执行完即结束,并不会保存

结果返回颜色

  1. 绿色: 代表被管理端主机没有被修改
  2. 黄色: 代表被管理端主机发现变更
  3. 红色: 代表出现了故障,注意查看提示

ansible常用模块

ansible命令模块

1.command

  1. [root@m01 ~]# ansible 'web_group' -m command -a 'free -m'
  2. web02 | CHANGED | rc=0 >>
  3. total used free shared buff/cache available
  4. Mem: 972 140 489 7 342 658
  5. Swap: 1023 0 1023
  6. web01 | CHANGED | rc=0 >>
  7. total used free shared buff/cache available
  8. Mem: 972 113 412 13 446 669
  9. Swap: 1023 0 1023

2.shell

  1. [root@m01 ~]# ansible 'web_group' -m shell -a 'ps -ef|grep nginx'
  2. web02 | CHANGED | rc=0 >>
  3. root 12584 12583 0 20:16 pts/1 00:00:00 /bin/sh -c ps -ef|grep nginx
  4. root 12586 12584 0 20:16 pts/1 00:00:00 grep nginx
  5. web01 | CHANGED | rc=0 >>
  6. root 14575 14570 0 12:16 pts/1 00:00:00 /bin/sh -c ps -ef|grep nginx
  7. root 14577 14575 0 12:16 pts/1 00:00:00 grep nginx

1)command不支持特殊符号

2)shell模块支持特殊符号

3)不指定-m 默认使用的是command模块

3.script

  1. #编写脚本
  2. [root@m01 ~]# vim vsftpd.sh
  3. #!/usr/bin/bash
  4. mkdir /tmp/zls
  5. [root@m01 ~]# ansible 'web01' -m script -a '/root/vsftpd.sh'
  6. [root@m01 ~]# ansible 'web01' -m shell -a 'ls -l /tmp'

ansible软件管理模块

4.yum

  1. [root@m01 ~]# ansible 'web_group' -m yum -a 'name=vsftpd state=present'
  2. #相当于:yum install -y vsftpd
  3. [root@m01 ~]# ansible 'web_group' -m yum -a 'name=https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm state=present'
  4. #相当于:yum install -y https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-agent-4.0.0-2.el7.x86_64.rpm
  5. [root@m01 ~]# ansible 'web_group' -m yum -a 'name=file:///root/nagios-4.4.3-1.el7.x86_64.rpm state=present'
  6. #相当于:yum localinstall -y nagios-4.4.3-1.el7.x86_64.rpm
  7. [root@m01 ~]# ansible 'web_group' -m yum -a 'name=vsftpd state=absent'
  8. #相当于:yum remove -y vsftpd
  9. name
  10. httpd #指定要安装的软件包名称
  11. file:// #指定本地安装路径(yum localinstall 本地rpm包)
  12. http:// #指定yum源(从远程仓库获取rpm包)
  13. state #指定使用yum的方法
  14. installed,present #安装软件包
  15. removed,absent #移除软件包
  16. latest #安装最新软件包

5.yum_repository

  1. - name: Add repository
  2. yum_repository:
  3. name: epel
  4. description: EPEL YUM repo
  5. baseurl: https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
  6. #添加yum仓库
  7. ansible 'web_group' -m yum_repository -a 'name=zls_epel,zls_base description=EPEL baseurl=https://download.fedoraproject.org/pub/epel/$releasever/$basearch/ gpgcheck=no enabled=yes file=zls_epel'
  8. #添加mirrorlist
  9. ansible 'web_group' -m yum_repository -a 'name=zls_epel description=EPEL baseurl=https://download.fedoraproject.org/pub/epel/$releasever/$basearch/ gpgcheck=no enabled=yes file=epel mirrorlist=http://mirrorlist.repoforge.org/el7/mirrors-rpmforge'
  10. #删除yum仓库
  11. ansible 'web_group' -m yum_repository -a 'name=zls_epel,zls_base file=zls_epel state=absent'
  12. #修改yum仓库
  13. ansible 'web_group' -m yum_repository -a 'name=epel description=EPEL baseurl=https://download.fedoraproject.org/pub/epel/$releasever/$basearch/ gpgcheck=no enabled=no file=epel'
  14. name #指定仓库名字
  15. description #添加描述(repo文件中的name)
  16. baseurl #指定yum仓库的地址
  17. gpgcheck #是否开启校验
  18. yes
  19. no
  20. enabled #是否启用yum仓库
  21. yes
  22. no
  23. file #指定仓库文件名
  24. state
  25. absent #删除yum仓库
  26. present #创建yum仓库
  27. ansible 'web_group' -m yum_repository -a 'name=zls_yum description=EPEL baseurl=http://www.driverzeng.com gpgcheck=no enabled=no file=zls'

ansible文件管理模块

1.copy

  1. - name: Copy file with owner and permissions
  2. copy:
  3. src: /srv/myfiles/foo.conf
  4. dest: /etc/foo.conf
  5. owner: foo
  6. group: foo
  7. mode: '0644'
  8. #推送文件
  9. [root@m01 ~]# ansible 'web_group' -m copy -a 'src=/root/index.html dest=/var/www/html owner=root group=root mode=0644'
  10. #推送文件并备份
  11. [root@m01 ~]# ansible 'web_group' -m copy -a 'src=/root/index.html dest=/var/www/html owner=root group=root mode=0644 backup=yes'
  12. #编辑nfs配置文件
  13. [root@m01 ~]# ansible 'web_group' -m copy -a 'content="/data 172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)" dest=/etc/exports'
  14. src #指定推送的源文件
  15. dest #指定推送的目标位置
  16. owner #指定属主
  17. group #指定属组
  18. mode #指定权限(数字方式)
  19. content #在指定文件中添加内容
  20. backup #是否备份(注意:控制端和被控端,内容不一致才会备份)
  21. yes
  22. no

2.file

  1. - name: Create an insecure file
  2. file:
  3. path: /work
  4. owner: root
  5. group: root
  6. mode: 0755
  7. #创建目录 mkdir
  8. [root@m01 ~]# ansible 'web_group' -m file -a 'path=/backup state=directory owner=adm group=adm mode=0700'
  9. #递归创建目录并授权chown -R chmod -R
  10. [root@m01 ~]# ansible 'web_group' -m file -a 'path=/zls/mysql/db01 state=directory owner=adm group=adm mode=0700 recurse=yes'
  11. #创建文件(前提条件,上级目录必须存在) touch
  12. [root@m01 ~]# ansible 'web_group' -m file -a 'path=/root/zls.txt state=touch'
  13. #删除目录 rm -fr
  14. [root@m01 ~]# ansible 'web_group' -m file -a 'path=/backup state=absent'
  15. #做软链接 ln -s
  16. [root@m01 ~]# ansible 'web_group' -m file -a 'src=/root/zls.txt dest=/root/zls.txt.ori state=link'
  17. src #指定软链接的源文件
  18. dest #指定软连接的目标文件
  19. path #指定创建目录或文件
  20. state
  21. touch #创建文件
  22. directory #创建目录
  23. absent #删除目录或文件
  24. link #做软链接
  25. owner #指定属主
  26. group #指定属组
  27. mode #指定权限
  28. recurse #递归授权
  29. yes
  30. no

3.get_url

  1. - name: Download foo.conf
  2. get_url:
  3. url: http://example.com/path/file.conf
  4. dest: /etc/foo.conf
  5. mode: '0440'
  6. #下载worldpress代码
  7. [root@m01 ~]# ansible 'web_group' -m get_url -a 'url=http://test.driverzeng.com/Nginx_Code/wordpress-5.0.3-zh_CN.tar.gz dest=/root mode=0777'
  8. #下载并校验MD5
  9. [root@m01 ~]# ansible 'web_group' -m get_url -a 'url=http://test.driverzeng.com/Nginx_Code/test.txt dest=/root mode=0777 checksum=md5:ba1f2511fc30423bdbb183fe33f3dd0f'
  10. url #指定下载文件的url
  11. dest #指定下载的位置
  12. mode #指定下载后的权限
  13. checksum #校验
  14. md5 #md5校验
  15. sha256 #sha256校验

ansible服务管理模块

1.service,systemd

  1. [root@m01 ~]# ansible 'web_group' -m systemd -a 'name=httpd state=stopped enabled=yes'
  2. [root@m01 ~]# ansible 'web_group' -m systemd -a 'name=httpd state=started enabled=yes'
  3. [root@m01 ~]# ansible 'web_group' -m systemd -a 'name=httpd state=restarted enabled=yes'
  4. [root@m01 ~]# ansible 'web_group' -m systemd -a 'name=httpd state=reloaded enabled=yes'
  5. name #指定服务名称
  6. state
  7. started #启动
  8. stopped #停止
  9. restarted #重启
  10. reloaded #重载
  11. enabled #是否开机自启
  12. yes
  13. no

ansible用户管理模块

1.group

  1. - name: Ensure group "somegroup" exists
  2. group:
  3. name: somegroup
  4. state: present
  5. #创建组
  6. [root@m01 ~]# ansible 'web_group' -m group -a 'name=www gid=666 state=present'
  7. #删除组
  8. [root@m01 ~]# ansible 'web_group' -m group -a 'name=www gid=666 state=absent'
  9. name #指定组名
  10. gid #指定gid
  11. state
  12. present #创建
  13. absent #删除

2.user

  1. - name: Create a 2048-bit SSH key for user jsmith in ~jsmith/.ssh/id_rsa
  2. user:
  3. name: jsmith
  4. generate_ssh_key: yes
  5. ssh_key_bits: 2048
  6. ssh_key_file: .ssh/id_rsa
  7. #创建用户
  8. [root@m01 ~]# ansible 'web_group' -m user -a 'name=www uid=666 group=www state=present shell=/sbin/nologin create_home=false'
  9. #删除用户
  10. [root@m01 ~]# ansible 'web_group' -m user -a 'name=www uid=666 state=absent'
  11. #创建用户的同时创建密钥对
  12. [root@m01 ~]# ansible 'web_group' -m user -a 'name=zls generate_ssh_key=yes ssh_key_bits=2048 ssh_key_file=.ssh/id_rsa'
  13. name #指定用户名
  14. uid #指定uid
  15. group #指定属组
  16. groups #指定附加组
  17. state
  18. present #创建用户
  19. absent #删除用户
  20. shell #指定用户登录的shell
  21. /bin/bash
  22. /sbin/nologin
  23. create_home #是否创建家目录
  24. true
  25. false
  26. comment #添加注释
  27. generate_ssh_key #创建密钥对
  28. ssh_key_bits #指定密钥对长度
  29. ssh_key_file #指定密钥文件
  30. #将明文密码进行hash加密,然后进行用户创建
  31. [root@m01 ~]# ansible web_group -m debug -a "msg={{ 'zls' | password_hash('sha512', 'salt') }}" -i ./hosts
  32. web01 | SUCCESS => {
  33. "msg": "$6$salt$gaWhNcZweYlKQcLU1CqyY/UbYqIeUffVz6ESj87aMNfMX.xYBx0Z.67wzLN/hkkxmNut7SvkksPZ2Zlrse98m/"
  34. }
  35. web02 | SUCCESS => {
  36. "msg": "$6$salt$gaWhNcZweYlKQcLU1CqyY/UbYqIeUffVz6ESj87aMNfMX.xYBx0Z.67wzLN/hkkxmNut7SvkksPZ2Zlrse98m/"
  37. }
  38. #创建用户
  39. [root@m01 ~]# ansible web_group -m user -a 'name=zls1 password=$6$salt$gaWhNcZweYlKQcLU1CqyY/UbYqIeUffVz6ESj87aMNfMX.xYBx0Z.67wzLN/hkkxmNut7SvkksPZ2Zlrse98m/ create_home=true shell=/bin/bash' -i ./hosts
  40. uid #指定用户的uid
  41. group #指定用户组名称
  42. groups #指定附加组名称
  43. password #给用户添加密码(单引号)
  44. shell #指定用户登录shell
  45. create_home #是否创建家目录

ansible的定时任务

cron

  1. # 正常使用crond服务
  2. [root@m01 ~]# crontab -l
  3. * * * * * /bin/sh /server/scripts/yum.sh
  4. # 使用ansible添加一条定时任务
  5. [root@m01 ~]# ansible web_group -m cron -a "minute=* hour=* day=* month=* weekday=* job='/bin/sh /server/scripts/test.sh'"
  6. [root@m01 ~]# ansible web_group -m cron -a "job='/bin/sh /server/scripts/test.sh'"
  7. # 设置定时任务注释信息,防止重复,name设定
  8. [root@m01 ~]# ansible web_group -m cron -a "name='cron01' job='/bin/sh /server/scripts/test.sh'"
  9. # 删除相应定时任务
  10. [root@m01 ~]# ansible web_group -m cron -a "name='ansible cron02' minute=0 hour=0 job='/bin/sh /server/scripts/test.sh' state=absent"
  11. # 注释相应定时任务,使定时任务失效
  12. [root@m01 scripts]# ansible web_group -m cron -a "name='ansible cron01' minute=0 hour=0 job='/bin/sh /server/scripts/test.sh' disabled=no"

mount

  1. [root@m01 ~]# ansible web_group -m mount -a "src=172.16.1.31:/data path=/data fstype=nfs opts=defaults state=present"
  2. [root@m01 ~]# ansible web01 -m mount -a "src=172.16.1.31:/data path=/data fstype=nfs opts=defaults state=mounted"
  3. [root@m01 ~]# ansible web02 -m mount -a "src=172. 16.1.31:/data path=/data fstype=nfs opts=defaults state=unmounted"
  4. [root@m01 ~]# ansible web -m mount -a "src=172.16.1.31:/data path=/data fstype=nfs opts=defaults state=absent"
  5. present # 开机挂载,仅将挂载配置写入/etc/fstab
  6. mounted # 挂载设备,并将配置写入/etc/fstab
  7. unmounted # 卸载设备,不会清除/etc/fstab写入的配置
  8. absent # 卸载设备,会清理/etc/fstab写入的配置

ansible防火墙模式

selinux

  1. #修改配置文件关闭selinux,必须重启
  2. [root@m01 ~]# ansible web_group -m selinux -a 'state=disabled' -i ./hosts
  3. [WARNING]: SELinux state temporarily changed from 'enforcing' to 'permissive'. State change will take effect next reboot.
  4. web01 | CHANGED => {
  5. "ansible_facts": {
  6. "discovered_interpreter_python": "/usr/bin/python"
  7. },
  8. "changed": true,
  9. "configfile": "/etc/selinux/config",
  10. "msg": "Config SELinux state changed from 'enforcing' to 'disabled'",
  11. "policy": "targeted",
  12. "reboot_required": true,
  13. "state": "disabled"
  14. }
  15. web02 | CHANGED => {
  16. "ansible_facts": {
  17. "discovered_interpreter_python": "/usr/bin/python"
  18. },
  19. "changed": true,
  20. "configfile": "/etc/selinux/config",
  21. "msg": "Config SELinux state changed from 'enforcing' to 'disabled'",
  22. "policy": "targeted",
  23. "reboot_required": true,
  24. "state": "disabled"
  25. }
  26. #临时关闭
  27. [root@m01 ~]# ansible web_group -m shell -a 'setenforce 0' -i ./hosts
  28. web02 | CHANGED | rc=0 >>
  29. web01 | CHANGED | rc=0 >>
  30. [root@m01 ~]# ansible web_group -m shell -a 'getenforce' -i ./hosts
  31. web02 | CHANGED | rc=0 >>
  32. Permissive
  33. web01 | CHANGED | rc=0 >>
  34. Permissive

firewalld

  1. [root@m01 ~]# ansible web_group -m firewalld -a 'service=http permanent=yes state=enabled' -i ./hosts
  2. [root@m01 ~]# ansible web_group -m firewalld -a "service=http immediate=yes permanent=yes state=enabled" -i ./hosts
  3. [root@m01 ~]# ansible web_group -m firewalld -a "port=8080-8090/tcp immediate=yes permanent=yes state=enabled" -i ./hosts
  4. service #指定开放或关闭的服务名称
  5. port #指定开放或关闭的端口
  6. permanent #是否添加永久生效
  7. state #开启或者关闭
  8. enabled
  9. disabled
  10. zone #指定配置某个区域
  11. rich_rule #配置辅规则
  12. masquerade #开启地址伪装
  13. immediate #临时生效
  14. source #指定来源IP

ansible主机信息模块

  1. ansible web01 -m setup
  2. ansible web01 -m setup -a 'filter= ' #查询单独产参数模式
  3. ansible_all_ipv4_addresses:仅显示ipv4的信息。
  4. ansible_devices:仅显示磁盘设备信息。
  5. ansible_distribution:显示是什么系统,例:centos,suse等。
  6. ansible_distribution_major_version:显示是系统主版本。
  7. ansible_distribution_version:仅显示系统版本。
  8. ansible_machine:显示系统类型,例:32位,还是64位。
  9. ansible_eth0:仅显示eth0的信息。
  10. ansible_hostname:仅显示主机名。
  11. ansible_kernel:仅显示内核版本。
  12. ansible_lvm:显示lvm相关信息。
  13. ansible_memtotal_mb:显示系统总内存。
  14. ansible_memfree_mb:显示可用系统内存。
  15. ansible_memory_mb:详细显示内存情况。
  16. ansible_swaptotal_mb:显示总的swap内存。
  17. ansible_swapfree_mb:显示swap内存的可用内存。
  18. ansible_mounts:显示系统磁盘挂载情况。
  19. ansible_processor:显示cpu个数(具体显示每个cpu的型号)。
  20. ansible_processor_vcpus:显示cpu个数(只显示总的个数)。

自动化运维工具-Ansible基础的更多相关文章

  1. 自动化运维工具-Ansible基础及Ansible Ad-Hoc

    第58章 Ansible 目录 第58章 Ansible 一.Ansible基础概述 1.1)什么是Ansible 1.2)Ansible可以完成哪些功能呢?1.3)Ansible特点 1.4)Ans ...

  2. 自动化运维工具Ansible详细部署 (转载)

    自动化运维工具Ansible详细部署 标签:ansible 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://sofar.blog. ...

  3. CentOS7Linux中自动化运维工具Ansible的安装,以及通过模块批量管理多台主机

    使用自动化运维工具Ansible集中化管理服务器 Ansible概述 Ansible是一款为类Unix系统开发的自由开源的配置和自动化工具.它用Python写成,类似于saltstack和Puppet ...

  4. 自动化运维工具Ansible介绍

    一个由 Python 编写的强大的配置管理解决方案.尽管市面上已经有很多可供选择的配置管理解决方案,但他们各有优劣,而 ansible 的特点就在于它的简洁. 让 ansible 在主流的配置管理系统 ...

  5. 自动化运维工具Ansible详细部署 - 人生理想在于坚持不懈 - 51CTO技术博客

    自动化运维工具Ansible详细部署 - 人生理想在于坚持不懈 - 51CTO技术博客 自动化运维工具Ansible详细部署

  6. 在CentOS7.6上安装自动化运维工具Ansible以及playbook案例实操

    前言 Ansible是一款优秀的自动化IT运维工具,具有远程安装.远程部署应用.远程管理能力,支持Windows.Linux.Unix.macOS和大型机等多种操作系统. 下面就以CentOS 7.6 ...

  7. 自动化运维工具-Ansible之7-roles

    自动化运维工具-Ansible之7-roles 目录 自动化运维工具-Ansible之7-roles Ansible Roles基本概述 Ansible Roles目录结构 Ansible Roles ...

  8. 自动化运维工具-Ansible之6-Jinja2模板

    自动化运维工具-Ansible之6-Jinja2模板 目录 自动化运维工具-Ansible之6-Jinja2模板 Ansible Jinja2模板概述 Ansible Jinja2模板使用 Ansib ...

  9. 自动化运维工具-Ansible之5-流程控制

    自动化运维工具-Ansible之5-流程控制 目录 自动化运维工具-Ansible之5-流程控制 playbook条件语句 单条件 多条件 多条件运算 示例 playbook循环语句 with_ite ...

随机推荐

  1. mysql-5.7.21-winx64安装教程

    1 . 下载对用的版本信息 地址是:https://dev.mysql.com/downloads/mysql/ 2 . 解压到目录 D:\tools\mysql\mysql-5.7.21-winx6 ...

  2. ffmpeg+nginx 实现rtsp转rtmp并通过nginx转发

    Windows安装 ffmpeg ffmpeg windows版下载地址https://ffmpeg.zeranoe.com/builds/ static版本就行 配置环境变量:下载的压缩包解压后的路 ...

  3. JavaScript数组循环

    JavaScript数组循环 一.前言 利用Javascript map(),reduce()和filter()数组方法可以遍历数组.而不是积累起来for循环和嵌套来处理列表和集合中的数据,利用这些方 ...

  4. C语言搬书学习第一记 —— 认识一个简单程序的细节

    #include<stdio.h> /*告诉编译器把stdio.h 中的内容包含在当前程序中,stdio.h是C编译器软件包的标准部分,它提供键盘输入和 屏幕输入的支持studio.h文件 ...

  5. 一道ctf-内存取证volatility的学习使用

    环境:kali 0x00 volatility官方文档 https://github.com/volatilityfoundation/volatility 在分析之前,需要先判断当前的镜像信息,分析 ...

  6. 解密国内BAT等大厂前端技术体系-腾讯篇(长文建议收藏)

    1 引言 为了了解当前前端的发展趋势,让我们从国内各大互联网大厂开始,了解他们的最新动态和未来规划.这是解密大厂前端技术体系的第三篇,前两篇已经讲述了阿里和百度在前端技术这几年的技术发展.这一篇从腾讯 ...

  7. 使用Visual Studio Code进行远程开发

    微软的VS code能够适应不同开发环境,提供对多种语言的支持,使得使用VS code开发变得很流行了.因为各种原因(比如在本地设置开发环境困难,或者繁琐,或者开发环境没有图形界面),我们可能需要远程 ...

  8. 前端开发规范:3-CSS

    尽量使用缩写属性 border-top-style: none; font-family: palatino, georgia, serif; font-size: 100%; line-height ...

  9. Shell批量SSH免交互登录认证

    脚本实现功能:批量或单个SSH免交互登录认证 脚本应用场景:当部署集群时,大多数实现要配置好管理节点与从节点的SSH免交互登录,针对这样的情况,写了下面脚本,简化工作. 脚本支持系统:Ubuntu和C ...

  10. 第一篇:C++之hello world

    1.编辑器:Microsoft Visual C++ 2010,下载安装 2.新建项目 代码: #include <iostream>#include <Windows.h>/ ...