ansible

Ansible是一款无需代理的配置管理工具,它使用SSH连接远程主机,实现应用部署、配置管理和更新。Ansible具有幂等性,能确保每次操作都一致。它使用模块化设计,包括核心模块和自定义模块,并通过主机清单定义管理的主机。安装过程涉及多个依赖包,如PyYAML和paramiko。Ansible通过命令行或Playbooks进行操作,提供丰富的选项和连接方式。此外,它支持权限升级、角色定义和YAML格式的配置文件。
摘要由CSDN通过智能技术生成

ansible
简介
ansible是一款远程的配置管理系统
常见与ansible相同的管理系统
fabric
puppet (ruby)
saltstack (python)
chef
cfengine
func
对管理的主机进行,应用部署,应用发布,备份配置
ansible的操作是幂等的
发布应基于灰度实现,每次下线一台主机,更新应用
或蓝绿实现,每次更新一批.
保证每台服务器的业务不存在问题.
无需其他工具,即通过ssh进行连接
被管理的主机,通过特定的程序进行操作,并且该程序可以获取管理员权限.
通过ssh 连接,
以普通用户登录,普通用户具有合适的sudo 权限
某一操作出现问题,进行快速失败,并再次执行.
使用模块进行实现,内部采用多级架构
核心模块
core Modules 实现大部分基础功能
自定义模块
custom Modules 实现扩展功能
模块通过连接插件,进行管理
connection Plugins
被管理的主机通过主机清单定义
拥有 通知插件,实现发送邮件,记录日志.
play books 定义 动作
使用YAML语言
ansible 拥有两种实现方式
通过命令行实现
通过 play books 实现
安装
yum 安装
yum -y install epel-release
yum clean all
yum info ansible
yum install ansible
插件
PyYAML-3.10-11.el7.x86_64.rpm
解析YAML格式的程序包
libyaml-0.1.4-11.el7_0.x86_64.rpm
libtomcrypt-1.17-26.el7.x86_64.rpm
python-backports-1.0-8.el7.x86_64.rpm
python-cffi-1.6.0-5.el7.x86_64.rpm
python-backports-ssl_match_hostname-3.4.0.2-4.el7.noarch.rpm
libtommath-0.42.0-6.el7.x86_64.rpm
python-enum34-1.0.4-1.el7.noarch.rpm
python-ipaddress-1.0.16-2.el7.noarch.rpm
python-httplib2-0.9.1-3.el7.noarch.rpm
ansible-2.3.1.0-3.el7.noarch.rpm
python-idna-2.0-1.el7.noarch.rpm
python-markupsafe-0.11-10.el7.x86_64.rpm
python-paramiko-2.1.1-2.el7.noarch.rpm
ssh远程连接模块
python-ply-3.4-10.el7.noarch.rpm
python-pycparser-2.14-1.el7.noarch.rpm
python-setuptools-0.9.8-4.el7.noarch.rpm
python-jinja2-2.7.2-2.el7.noarch.rpm
模板插件
python2-pyasn1-0.1.9-7.el7.noarch.rpm
python2-crypto-2.6.1-15.el7.x86_64.rpm
sshpass-1.06-2.el7.x86_64.rpm
python2-cryptography-1.3.1-3.el7.x86_64.rpm
python-babel-0.9.6-8.el7.noarch.rpm
python-six-1.9.0-2.el7.noarch.rpm
文件
/etc/ansible
/etc/ansible/ansible.cfg
配置文件
roles_path = /etc/ansible/roles:/usr/share/ansible/roles
定义了角色目录 : 分隔两个路径
定义颜色
[colors]

highlight = white

verbose = blue

warn = bright purple

error = red

debug = dark gray

deprecate = purple

skip = cyan

unreachable = red

ok = green

changed = yellow

diff_add = green

diff_remove = red

diff_lines = cyan

            [defaults]

some basic default values…

inventory = /etc/ansible/hosts

library = /usr/share/my_modules/

module_utils = /usr/share/my_module_utils/

remote_tmp = ~/.ansible/tmp

local_tmp = ~/.ansible/tmp

forks = 5 并行执行的主机数

poll_interval = 15

sudo_user = root

ask_sudo_pass = True

ask_pass = True

transport = smart

remote_port = 22 远程主机使用的端口

module_lang = C

module_set_locale = False

        /etc/ansible/hosts

主机清单
只有记录在该主机中的主机才可被管控
可以在主机清单中定义连接的用户名称,以及密码.
同样可以使用ssh 无秘钥连接
/etc/ansible/roles
角色目录
/usr/bin/ansible
主程序
/usr/share/ansible
/usr/share/ansible/roles
存放定义的角色
命令行
命令格式
ansible [options]
常用格式
ansible HOST-PATTERN -m MOD_NAME -a MOD_ARGS -f FORKS -C -u USERNAME -c CONNECTION
选项分为3类
Options:
–ask-vault-pass ask for vault password
-B SECONDS, –background=SECONDS
run asynchronously, failing after X seconds
(default=N/A)

          -D, --diff            when changing (small) files and templates, show the
                                differences in those files; works great with --check
          -e EXTRA_VARS, --extra-vars=EXTRA_VARS
                                set additional variables as key=value or YAML/JSON

          -h, --help            show this help message and exit

          -l SUBSET, --limit=SUBSET
                                further limit selected hosts to an additional pattern

          --new-vault-password-file=NEW_VAULT_PASSWORD_FILE
                                new vault password file for rekey
          -o, --one-line        condense output
          --output=OUTPUT_FILE  output file name for encrypt or decrypt; use - for
                                stdout
          -P POLL_INTERVAL, --poll=POLL_INTERVAL
                                set the poll interval if using -B (default=15)

          -t TREE, --tree=TREE  log output to this directory
          --vault-password-file=VAULT_PASSWORD_FILE
                                vault password file
          -v, --verbose         verbose mode (-vvv for more, -vvvv to enable
                                connection debugging)
          --version             show program's version number and exit
          -m MODULE_NAME, --module-name=MODULE_NAME
                    module name to execute (default=command)

指明使用的模块的名称
-M MODULE_PATH, –module-path=MODULE_PATH
specify path(s) to module library (default=None)
模块的路径?
-a MODULE_ARGS, –args=MODULE_ARGS
module arguments
指定模块的参数
-C, –check don’t make any changes; instead, try to predict some
of the changes that may occur
测试执行
-f FORKS, –forks=FORKS
specify number of parallel processes to use
(default=5)
将所有需要管控的主机进行分批并行处理.默认每批5个.
-i INVENTORY, –inventory-file=INVENTORY
specify inventory host path
(default=/etc/ansible/hosts) or comma separated host
list.
指明主机的清单文件
–list-hosts outputs a list of matching hosts; does not execute
anything else
列出匹配的目标主机
–syntax-check perform a syntax check on the playbook, but do not
execute it
检测play books 的语法是否存在错误.
Connection Options: 连接选项
-k, –ask-pass ask for connection password
–private-key=PRIVATE_KEY_FILE, –key-file=PRIVATE_KEY_FILE
use this file to authenticate the connection

        -T TIMEOUT, --timeout=TIMEOUT
                            override the connection timeout in seconds
       
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值