ansible 安装使用
ansible
ansible源码安装
yum -y install python-jinja2 PyPAML python-parmiko python-babel python-crypto
tar -zxf ansible-1.5.4.tar.gz
cd ansible-1.5.4
python setup.py build
python setup.py install
mkdir /etc/ansible
cp - examples/* /etc/ansible
ansible yum安装
cd /etc/yum.repos.d/
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.rep
yum -y install python-jinja2 PyPAML python-parmiko python-babel python-crypto ansible
ansible 配置文件的作用
rpm -ql ansible
/etc/ansible/ansible.cfg
/etc/ansible/hosts #配置文件,定义了识别的所有主机
/etc/ansible/roles
/usr/bin/ansible
/usr/bin/ansible-console
/usr/bin/ansible-doc #文档
/usr/bin/ansible-galaxy
/usr/bin/ansible-playbook ###剧本
ansible配置 /etc/ansible/hosts (连接的主机)
cat /etc/ansible/hosts
[webserver]
192.168.1.104
[dbserver]
192.168.1.105
ansible ssh免密码认证
ssh-kengen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.104
ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.1.105
ansible 命令使用
使用 -m ping模块,判断客户机是否在线
ansible all -m ping
查看主机时间
ansible all -m command -a "date"
查看ansilbe 使用方法
man ansible
ansible基本语法
ansible <host-pattern> [-m module_name] [-a args] [options]
-m command 默认模块,可以不用写。
查看docker服务器是否启用
ansible all -m command -a "systemctl status docker.service"
ansible 所有模块
ansible-doc -l 查看ansilbe所有模块
ansible copy模块使用方法、
ansible-doc -s copy
[root@localhost yum.repos.d]# ansible-doc -s copy
- name: Copies files to remote locations.
action: copy
backup # Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly.
content # When used instead of 'src', sets the contents of a file directly to the specified value. This is for simple values, for anything complex or with
formatting please switch to the template module.
dest= # Remote absolute path where the file should be copied to. If src is a directory, this must be a directory too.
directory_mode # When doing a recursive copy set the mode for the directories. If this is not set we will use the system defaults. The mode is only set on directories
which are newly created, and will not affect those that already existed.
follow # This flag indicates that filesystem links, if they exist, should be followed.
force # the default is `yes', which will replace the remote file when contents are different than the source. If `no', the file will only be transferred if the
destination does not exist.
group # name of the group that should own the file/directory, as would be fed to `chown'
mode # mode the file or directory should be. For those used to `/usr/bin/chmod' remember that modes are actually octal numbers (like 0644). Leaving off the
leading zero will likely have unexpected results. As of version 1.8, the mode may be specified as a symbolic mode (for
example, `u+rwx' or `u=rw,g=r,o=r').
owner # name of the user that should own the file/directory, as would be fed to `chown'
remote_src # If False, it will search for src at originating/master machine, if True it will go to the remote/target machine for the src. Default is False.
Currently remote_src does not support recursive copying.
selevel # level part of the SELinux file context. This is the MLS/MCS attribute, sometimes known as the `range'. `_default' feature works as for `seuser'.
serole # role part of SELinux file context, `_default' feature works as for `seuser'.
setype # type part of SELinux file context, `_default' feature works as for `seuser'.
seuser # user part of SELinux file context. Will default to system policy, if applicable. If set to `_default', it will use the `user' portion of the policy if
available
src # Local path to a file to copy to the remote server; can be absolute or relative. If path is a directory, it is copied recursively. In this case, if path
ends with "/", only inside contents of that directory are copied to destination. Otherwise, if it does not end with "/",
the directory itself with all contents is copied. This behavior is similar to Rsync.
validate # The validation command to run before copying into place. The path to the file to validate is passed in via '%s' which must be present as in the example
below. The command is passed securely so shell features like expansion and pipes won't work.
拷贝命令
ansible all -m copy -a "src=/etc/yum.repos.d/epel-7.repo dest=/tmp"
检查拷贝是否成功
ansible all -m command -a "ls /tmp/"
ansible 使用cron 模块,定义每3分钟同步以下时间
[root@localhost yum.repos.d]# ansible-doc -s cron
1. 放置到/etc/crontab文件下
ansible all -m cron -a "name='sutom job' cron_file=/etc/crontab user=root minute=*/3 hour=* day=* month=* weekday=* job='/usr/sbin/ntpdate 192.168.1.1'"
2. 第二种方法
ansible all -m cron -a "name='sutom job' user=root minute=*/3 hour=* day=* month=* weekday=* job='/usr/sbin/ntpdate 192.168.1.1'"
3. 验证crontab 是否添加
ansible all -m command -a "crontab -l"
使用group模块新建mysql组
ansible all -m group -a "gid=306 system=yes name=mysql"
使用user模块新建mysql用户
ansible all -m user -a "group=mysql home=/home/mysql name=mysql createhome=yes"
通过ansible使用yum模块
ansible-doc -s yum
ansible all -m yum -a "state=present name=python-devel"
通过ansible使用service模块
ansible all -m service -a "state=started name=docker enabled=yes"
检查服务器启动状态
ansible all -m command -c "systemctl list-unit-files docker.service"
ansible playbooks
例子:
[root@localhost ~]# cat nginx.yaml
- hosts: all
remote_user: root
tasks:
- name: install nginx latest version
yum: state=latest name=nginx
- name: copy nginx configure file to hosts
copy: src=/root/nginx.conf dest=/etc/nginx/ force=yes
notify:
- restart nginx
handlers:
- name: restart nginx
service: state=restarted name=nginx.service
ansible 安装使用的更多相关文章
- 初探ansible安装
一.ansible介绍常用的自动化运维工具 Puppet —基于 Ruby 开发,采用 C/S 架构,扩展性强,基于 SSL,远程命令执行相对较弱SaltStack —基于 Python 开发,采用 ...
- Ansible安装配置Nginx
一.思路 现在一台机器上编译安装好nginx.打包,然后在用ansible去下发 cd /etc/ansible 进入ansible配置文件目录 mkdir roles/{common,install ...
- Ansible安装配置及使用
一.Ansible特点 1.不需要安装客户端,通过sshd通信 2.基于模块工作,模块可以由任何序言开发 3.不仅支持命令行使用模块,也支持编写yaml格式的playbook 4.支持sudo 5.有 ...
- Ansible安装配置
Ansible工具的安装与配置 Ansible基于SSH,不需要在远程端安装任何软件,只需要在管理端安装ansible及其组件即可. Ansible使用前提是已配置ssh密钥免登陆. 一.安装组件: ...
- ansible安装二进制kubernetes-1.14.1
主机信息: 主机IP 主机名 角色 10.10.3.181 k8s-m1 kube-apiserver,kube-controller-manager,kube-scheduler,etcd 10. ...
- Ansible安装部署以及常用模块详解
一. Ansible 介绍Ansible是一个配置管理系统configuration management system, python 语言是运维人员必须会的语言, ansible 是一个基于py ...
- 内网环境使用ansible安装software 需要外网时,如何绑定代理呢
内网环境使用ansible安装software 需要外网时,如何绑定代理呢? 方法一: 在ansible 的脚本里,yum install 的地方,添加语句: environment: https_p ...
- Ansible 安装与配置(一)
公司大概有200多云主机需要进行管理,但是如果通过手工管理费时还累最终结果也容易出错,所以考虑通过自动化的方式来管理云主机,目前开源的自动化工具,大家用的比较多的有Ansible和Saltstack这 ...
- Ansible安装及OS规划
Ansible安装 1.以管理用户mtnsadmin连接服务器后下载安装包(-O表示将下载的文件存放到指定的文件夹下,同时重命名下载的文件) sudo wget -O /etc/yum.re ...
- 【mac】ansible安装及基础使用
安装 环境释放 mac 10.12.5 #more /System/Library/CoreServices/SystemVersion.plist 安装命令 #ruby -e "$(cur ...
随机推荐
- 20145304 Java第八周学习报告
20145304<Java程序设计>第八周学习总结 教材学习内容总结 NIO NIO使用频道来衔接数据节点,在处理数据时,NIO可以让你设定缓冲区容量,在缓冲区中对感兴趣的数据区块进行标记 ...
- BZOJ4260 Codechef REBXOR 题解
题目大意: 有一个长度为n的序列,求1≤l1≤r1<l2≤r2≤n使得(⊕r1i=l1ai)+(⊕r2i=l2ai)最大,输出这个最大值. 思路: 用Trie求出前缀异或和以及后缀异或和,再求出 ...
- 【BZOJ】2115: [Wc2011] Xor
http://www.lydsy.com/JudgeOnline/problem.php?id=2115 题意:给出一个n个点m条边的无向连通边加权图,求1-n的某条路径使得异或值最大(可以重复点可以 ...
- 【CodeVS】1993草地排水
题目描述 Description 在农夫约翰的农场上,每逢下雨,Bessie最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一套排水 ...
- 【bzoj2002】[Hnoi2010]Bounce 弹飞绵羊 link-cut-tree
2016-05-30 11:51:59 用一个next数组,记录点x的下一个点是哪个 查询时,moveroot(n+1),access(x),splay(x) ,输出size[ch[x][0]]即为答 ...
- 团队计划backlog
http://www.cnblogs.com/threemonkey/p/5388439.html
- Maya 脚本控制物体自转
在Maya中,我们可以用脚本来控制物体的自转方向,速度等等,步骤如下: 选择需要操作的物体object,打开通道盒Channel Box,点击编辑Edit,打开表达式Expressions面板 选择需 ...
- 将普通工程转为mvn标准工程(main resources)
It is sometimes required to change the default source folder working on the java project. One best e ...
- Java_Eclipse安装Git插件
一.从官网选择系统版本下载Git并安装 地址:https://git-scm.com/downloads/ 二.打开Eclipse 1. 第一种安装方法: help-->Install New ...
- JQ写法和js写法 方法函数化
<script> $(function () { $('#head').click=function () { alert($(this).html()) } }) </script ...