Ansible安装配置和基本使用

Ansible安装配置和基本使用 。小编来告诉你更多相关信息 。
Ansible安装配置和基本使用为网友解答Ansible安装配置和基本使用方面的内容,具体内容如下:
一、Ansible安装Ansible的安装方法主要有以下四种:
1.1 yum使用EPEL源安装mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backupmv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backupwget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repoyum clean all && yum makecache# 可以使用以下三种方式查看ansible包的信息yum info ansibleyum list ansibleyum list | grep ansibleansible.noarch2.9.27-1.el7epelansible-collection-microsoft-sql.noarch1.1.0-1.el8AppStreamansible-collection-redhat-rhel_mgmt.noarch1.0.0-2.el8AppStreamansible-doc.noarch2.9.27-1.el7epelansible-freeipa.noarch0.3.8-1.el8AppStreamansible-freeipa-tests.noarch0.3.8-1.el8AppStreamansible-inventory-grapher.noarch2.4.4-1.el7epelansible-lint.noarch3.5.1-1.el7epelansible-openstack-modules.noarch0-20140902git79d751a.el7epelansible-pcp.noarch2.2.1-1.el8AppStreamansible-python3.noarch2.9.27-1.el7epelansible-review.noarch0.13.4-1.el7epelansible-test.noarch2.9.27-1.el7epelcentos-release-ansible-29.noarch1-2.el8extraskubernetes-ansible.noarch0.6.0-0.1.gitd65ebd5.el7epelpython2-ansible-runner.noarch1.0.1-1.el7epelpython2-ansible-tower-cli.noarch3.3.9-1.el7epelvim-ansible.noarch3.2-1.el7# 安装ansibleyum -y install ansibleansible --versionAnsible安装配置和基本使用 。小编来告诉你更多相关信息 。
Ansible安装配置和基本使用1.2 编译安装yum -y install python-jinja2 PyYAML python-paramiko python-babel python-crypto# 需要提前安装Python环境(略)wget https://releases.ansible.com/ansible/ansible-2.9.27.tar.gztar xf ansible-2.9.27.tar.gzcd ansible-2.9.27ls -altotal 160drwxr-xr-x2 root root4096 May 25 05:18 bindrwxr-xr-x2 root root4096 May 25 05:18 changelogsdrwxr-xr-x3 root root4096 May 25 05:18 contrib-rw-r--r--1 root root 35148 May 25 05:18 COPYINGdrwxr-xr-x6 root root4096 May 25 05:18 docsdrwxr-xr-x3 root root4096 May 25 05:18 examplesdrwxr-xr-x3 root root4096 May 25 05:18 hackingdrwxr-xr-x3 root root4096 May 25 05:18 libdrwxr-xr-x2 root root4096 May 25 05:18 licenses-rw-r--r--1 root root 13840 May 25 05:18 Makefile-rw-r--r--1 root root1731 May 25 05:18 MANIFEST.indrwxr-xr-x 10 root root4096 May 25 05:18 packaging-rw-r--r--1 root root7724 May 25 05:18 PKG-INFO-rw-r--r--1 root root5175 May 25 05:18 README.rst-rw-r--r--1 root root351 May 25 05:18 requirements.txt-rw-r--r--1 root root 12949 May 25 05:18 setup.py-rw-r--r--1 root root 28352 May 25 05:18 SYMLINK_CACHE.jsondrwxr-xr-x7 root root4096 May 25 05:18 testpython setup.py buildpython setup.py installmkdir /etc/ansiblecp -r examples/* /etc/ansible1.3 Git 源码安装git clone https://github.com/ansible/ansible.gitcd ansiblegit checkout stable-2.9Updating files: 100% (19674/19674), done.Branch \'stable-2.9\' set up to track remote branch \'stable-2.9\' from \'origin\'.Switched to a new branch \'stable-2.9\'source ./hacking/env-setup1.4 pip安装yum install python-pip python-develyum install gcc glibc-devel zibl-devel rpm-bulid openss1-devel pip install -U pip pip install ansible --upgrade

Ansible安装配置和基本使用

文章插图
二、Ansible相关文件说明2.1 配置文件
  • /etc/ansible/ansible.cfg:主配置文件,配置ansible工作特性;
  • /etc/ansible/hosts:主机清单文件,管理的目标主机地址清单;
  • /etc/ansible/roles/: 存放角色的目录 。
2.2 主配置文件介绍[defaults]#inventory = /etc/ansible/hosts# 主机列表配置文件#library =/usr/share/my_modules/# 库文件存放目录#remote_tmp = $HOME/.ansible/tmp# 临时py命令文件存放在远程主机目录#local_tmp = $HOME/.ansible/tmp# 本机的临时命令执行目录#forks = 5# 默认并发数#sudo_user = root# 默认sudo用户#ask_sudo_pass = True# 每次执行ansible命令是否询间ssh密码#ask_pass = True# 是否询问密码#remote_port = 22# 默认的远程登录端口host_key_checking = False# 检查对应服务器的host_key,建议取消注释log_path=/var/log/ansible.log# 日志文件,建议启用#module_name = command# 默认模块,可以修改为shell模块Ansible安装配置和基本使用 。小编来告诉你更多相关信息 。
Ansible安装配置和基本使用以上只是一小部分关于default的相关配置,还有其他更多的配置这里暂时不一一列举 。因为ansible的大部分参数都可以保持默认,无需更改 。但是当你的被管理机器数量增加以后,建议将forks数量适当的调整 。
温馨提示:由于Ansible不是一个服务,所以更改完配置后无无需进行重启操作(也没提供重启的操作方法),改完配置立即生效 。
2.3 Inventory主机清单文件主机清单文件,用大白话讲其实就是被整合在一个文件中的一组或者多组被管控的节点 。默认情况下,该清单文件为: