Ansible自动化运维笔记1(安装配置)
1.Ansible的安装##
pip install ansible==1.9.1
ansible1.9.1版本依赖的软件有
Python2.6以上版本
paramiko模块
PyYAML
Jinja2
httplib2
被管理端linux需要有python2.6以上的环境
2.Ansible配置运行环境##
1.配置文件路径
ini格式存储数据形式
ansible配置文件的查找顺序
(1).检查环境变量ANSIBLE_CONFIG指向的路径文件(export ANSIBLE_CONFIG=/etc/ansible.cfg)
(2).~/.ansible.cfg,检查当前目录下的ansible.cfg配置文件
(3)./etc/ansible.cfg 检查etc目录的配置文件
2.配置文件配置项
1.inventory:主机清单文件
2.libray:指向存放ansible模块的目录,
3.forks: 多进程跑任务,多进程数
4.sudo_user: 默认执行命令的用户
5.remote_port: 连接节点的管理端口,默认22
6.host_key_checking:是否检查ssh主机的秘钥,值可以写作true和false;(known_hosts中有了之前不通的秘钥信息,忽略)
7.timeout: 设置ssh连接的超时时间,单位是秒,不是数据返回的超时,切记
8.log_path: ansible默认是不记录日志的,如果要输出记录到日志文件中,可以设置一个文件存储ansible日志的文件(log_path = /var/log/ansible.log),模块会调用节点的syslog来记录,口令不会出现在日志中
3.无密码,公钥访问
# 管理端生成自己的公钥
$ ssh-keygen
(一路回车)
# 把公钥分发到节点上
$ ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.111
# 连接测试
$ ssh root@192.168.1.111
3.Ansible小试身手##
[admin@host-10-187-196-225 ~]$ ansible --version
ansible 1.9.1
configured module search path = None
1.联通性测试
/tmp/hosts(里面写一条数据10.187.109.116)
2.分组主机都进行联通性检测
vim /tmp/hosts
[webservers]
10.187.109.116
10.189.92.46
4.Ansible在被管理节点上执行命令##
使用ansible提供的shell模块来跑
5.Ansible的帮助信息##
ansible-doc工具的使用
1.ansible-doc -l列出可使用的模块
[admin@host-10-187-196-225 tmp]$ ansible-doc -l
less 436
Copyright (C) 1984-2009 Mark Nudelman
less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less
a10_server Manage A10 Networks AX/SoftAX/Thunder/vThunder devices
a10_service_group Manage A10 Networks AX/SoftAX/Thunder/vThunder devices
a10_virtual_server Manage A10 Networks AX/SoftAX/Thunder/vThunder devices
acl Sets and retrieves file ACL information.
add_host add a host (and alternatively a group) to the ansible-playbook in-memory inventory
airbrake_deployment Notify airbrake about app deployments
alternatives Manages alternative programs for common commands
apache2_module enables/disables a module of the Apache2 webserver
apt Manages apt-packages
apt_key Add or remove an apt key
apt_repository Add and remove APT repositories
apt_rpm apt_rpm package manager
assemble Assembles a configuration file from fragments
assert Fail with custom message
at Schedule the execution of a command or script file via the at command.
authorized_key Adds or removes an SSH authorized key
azure create or terminate a virtual machine in azure
bigip_facts Collect facts from F5 BIG-IP devices
bigip_monitor_http Manages F5 BIG-IP LTM http monitors
bigip_monitor_tcp Manages F5 BIG-IP LTM tcp monitors
bigip_node Manages F5 BIG-IP LTM nodes
bigip_pool Manages F5 BIG-IP LTM pools
bigip_pool_member Manages F5 BIG-IP LTM pool members
bigpanda Notify BigPanda about deployments
boundary_meter Manage boundary meters
bower Manage bower packages with bower
bzr Deploy software (or files) from bzr branches
campfire Send a message to Campfire
capabilities Manage Linux capabilities
cloudformation create a AWS CloudFormation stack
command Executes a command on a remote node
composer Dependency Manager for PHP
copy Copies files to remote locations.
cpanm Manages Perl library dependencies.
cron Manage cron.d and crontab entries.
crypttab Encrypted Linux block devices
datadog_event Posts events to DataDog service
debconf Configure a .deb package
debug Print statements during execution
digital_ocean Create/delete a droplet/SSH_key in DigitalOcean
digital_ocean_domain Create/delete a DNS record in DigitalOcean
digital_ocean_sshkey Create/delete an SSH key in DigitalOcean
django_manage Manages a Django application.
2.ansible-doc -s列出模块支持的动作
[admin@host-10-187-196-225 tmp]$ ansible-doc -s shell
less 436
Copyright (C) 1984-2009 Mark Nudelman
less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Homepage: http://www.greenwoodsoftware.com/less
- name: E x e c u t e c o m m a n d s i n n o d e s .
action: shell
chdir # cd into this directory before running the command
creates # a filename, when it already exists, this step will *not* be run.
executable # change the shell used to execute the command. Should be an absolute path to the executable.
free_form= # The shell module takes a free form command to run, as a string. There's not an actual option named "free form". See the examples!
removes # a filename, when it does not exist, this step will *not* be run.
warn # if command warnings are on in ansible.cfg, do not warn about this particular line if set to no/false.
3.ansible-doc 模块名 显示该模块的描述和使用示例
$ ansible-doc shell
> SHELL
The [shell] module takes the command name followed by a list of
space-delimited arguments. It is almost exactly like the [command]
module but runs the command through a shell (`/bin/sh') on the
remote node.
Options (= is mandatory):
- chdir
cd into this directory before running the command [Default:
None]
- creates
a filename, when it already exists, this step will *not* be
run. [Default: None]
- executable
change the shell used to execute the command. Should be an
absolute path to the executable. [Default: None]
= free_form
The shell module takes a free form command to run, as a
string. There's not an actual option named "free form". See
the examples! [Default: None]
- removes
a filename, when it does not exist, this step will *not* be
run. [Default: None]
- warn
if command warnings are on in ansible.cfg, do not warn about
this particular line if set to no/false. [Default: True]
Notes: If you want to execute a command securely and predictably, it may be
better to use the [command] module instead. Best practices
when writing playbooks will follow the trend of using
[command] unless [shell] is explicitly required. When running
ad-hoc commands, use your best judgement. To sanitize any
variables passed to the shell module, you should use "{{ var |
quote }}" instead of just "{{ var }}" to make sure they don't
include evil things like semicolons.
EXAMPLES:
# Execute the command in remote shell; stdout goes to the specified
# file on the remote.
- shell: somescript.sh >> somelog.txt
# Change the working directory to somedir/ before executing the command.
- shell: somescript.sh >> somelog.txt chdir=somedir/
# You can also use the 'args' form to provide the options. This command
# will change the working directory to somedir/ and will only run when
# somedir/somelog.txt doesn't exist.
- shell: somescript.sh >> somelog.txt
args:
chdir: somedir/
creates: somelog.txt
4.ansible调试脚本过程中,获取执行过程详细信息,后面加上-vvv
Ansible自动化运维笔记1(安装配置)的更多相关文章
- 自动化运维工具SaltStack安装配置
SaltStack是一种全新的基础设置管理方式,部署轻松,在几分钟内可运作起来,扩展性好,很容易管理上万台服务器,速度够快,服务器之间秒级通讯.通过部署SaltStack环境,我们可以在成千上万台服务 ...
- Ansible自动化运维之介绍安装与简单使用
参考:http://blog.51cto.com/191226139/2066936 Ansible是什么 Ansible 简单的说是一个配置管理系统(configuration management ...
- ansible自动化运维工具的安装与使用
运行环境 centOS6.6 ansible ansible的功能还是比较多的,博主只用它在集群上进行批量部署软件和维护的功能,其他不多做研究,有需要的话这篇文章会慢慢补充. ansible特点 轻量 ...
- Ansible自动化运维笔记3(playbook)
1.基本语法 playbook文件格式为yaml语法.示例如下: 1.1 nginx.yaml --- - hosts: all tasks: - name: Install Nginx Packag ...
- Ansible自动化运维笔记2(Ansible的组件介绍)
1.Ansible Inventory (1)静态主机文件 默认的ansible invetory是/etc/hosts文件,可以通过ANSIBLE_HOSTS环境变量或者通过运行命令的时候加上-i ...
- Ansible自动化运维工具-上
[Ansible特点] 1)Ansible与saltstack均是基于Python语言开发的 2)安装使用简单,基于不同插件和模块实现各种软件,平台,版本的管理以及支持虚拟容器多层级的部署 3)不需要 ...
- ansible 自动化运维
Ansible 自动化运维 ansible安装epel #yum list all *ansible*#yum install *ansible*#yum info ansible#rpm -ql a ...
- Ansible 自动化运维工具
Ansible 自动化运维工具 Ansible是什么? Ansible是一个"配置管理工具"也是一个"自动化运维工具" Ansible 作用: Ansible是 ...
- 简单聊一聊Ansible自动化运维
一.Ansible概述 Ansible是今年来越来越火的一款开源运维自动化工具,通过Ansible可以实现运维自动化,提高运维工程师的工作效率,减少人为失误.Ansible通过本身集成的非常丰富的模块 ...
随机推荐
- easyUI中点击datagrid列标题排序
easyUI中点击datagrid的排序有两种,一种是本地的,一种是服务器的.本地的只能排序当前页,而服务器的可以对全部页进行排序.这里主要是分享下服务器排序. 1.为datagrid添加属性remo ...
- [JLOI2011]基因补全
1973: [JLOI2011]基因补全 Time Limit: 1 Sec Memory Limit: 256 MB Description 在生物课中我们学过,碱基组成了DNA(脱氧核糖核酸), ...
- SQL语句-delete语句
delete语句 delete语句用于删除表中已经存在的整行数据 Tbl_name关键词代表删除数据的目标表 Where子句代表被删除数据的满足条件,如果没有where子句则代 表所有表数据都删除 O ...
- 模块(module)
1.模块加载 import math //import后面跟模块名 from module1 import module11 //module1是一个大模块,里边有子模块module11,调用这个 ...
- C之多线程(例子很不错)
1.线程 线程池是一个树状结构. 多线程解决并发问题. 一个线程内部的执行顺序是线性的.而线程之间是乱序的. 若要创建一个多线程程序,它的参数必须是空指针类型. 变色龙程序: #define _CRT ...
- python使用上下文管理器实现sqlite3事务机制
如题,本文记录如何使用python上下文管理器的方式管理sqlite3的句柄创建和释放以及事务机制. 1.python上下文管理(with) python上下文管理(context),解决的是这样一类 ...
- 史上最大的CPU Bug(幽灵和熔断的OS&SQLServer补丁)
背景 最近针对我们的处理器出现了一系列的严重的bug.这种bug导致了两个情况,就是熔断和幽灵. 这就是这几天闹得人心惶惶的CPU大Bug.消息显示,以英特尔处理器为代表的现代CPU中,存在可以导致数 ...
- 《Python网络编程》学习笔记--UDP协议
第二章中主要介绍了UDP协议 UDP协议的定义(转自百度百科) UDP是OSI参考模型中一种无连接的传输层协议,它主要用于不要求分组顺序到达的传输中,分组传输顺序的检查与排序由应用层完成,提供面向事务 ...
- 下载vlc遭遇网络劫持
一次偶然的机遇,在公司下载"vlc播放器",下载之后安装完就变成了"搜狗手机助手".而且连续几次下载都是这样,我以为是我安装了搜狗输入法的缘故. ...
- 700名黑客无法攻破Trillium安全防护软件 欲以网络安全险获利
盖世汽车讯 据外媒报道,在2017 DEF CON黑客大会上,黑客们受邀入侵Car Hacking Village会场内的各类自动驾驶车辆.物联网网络安全公司--Trillium Incorporat ...