Ansible 简单使用

简介: 安装rpm -Uvh https://mirrors.zju.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpmyum install -y ansible 配置hostsvi /etc/ansible/hosts aly ansible_ssh_port=10011 ansible_ssh_host=127.

安装
rpm -Uvh https://mirrors.zju.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install -y ansible

配置hosts
vi /etc/ansible/hosts

aly ansible_ssh_port=10011 ansible_ssh_host=127.0.0.1
kaiping ansible_ssh_port=10013 ansible_ssh_host=127.0.0.1

 

hosts一些参数
ansible_ssh_host
#用于指定被管理的主机的真实IP
ansible_ssh_port
#用于指定连接到被管理主机的ssh端口号,默认是22
ansible_ssh_user
#ssh连接时默认使用的用户名
ansible_ssh_pass
#ssh连接时的密码
ansible_python_interpreter
#用来指定python解释器的路径,默认为/usr/bin/python 同样可以指定ruby 、perl 的路径


执行命令,说明:all 是所以都执行,可以改成组名
ansible all -m command -a 'mkdir -p /usr/local/nba'

执行复制
ansible all -m copy -a "src=/usr/local/1.txt dest=/usr/"
验证
ansible all -a "ls /usr/"

定义cron任务
ansible all -m cron -a'name="custom job" minute=*/3 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate
验证
ansible all -a "crontab -l"

yum安装
ansible all -m yum -a "state=present name=nload"
验证
ansible all -a "rpm -qa nload"

启动服务
ansible all -m service -a "state=started name=httpd enabled=yes"
验证

ansible all -m command -a 'rpm -Uvh https://mirrors.zju.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm'

相关文章
ansible的环境部署及简单使用
ansible的环境部署及简单使用
177 0
|
3月前
|
Serverless 网络安全 Python
Ansible原理和安装
Ansible原理和安装
40 1
|
运维 监控 数据可视化
Ansible Tower3.6.2的安装及简单使用
Ansible Tower3.6.2的安装及简单使用
365 0
Ansible Tower3.6.2的安装及简单使用
|
Shell 网络安全 开发工具
[Ansible专栏]Ansible安装和基本使用
[Ansible专栏]Ansible安装和基本使用
LXJ
05-Ansible模块的基本使用
05-Ansible模块的基本使用
LXJ
150 0
|
Shell
Ansible-playbook 简单实例(学习笔记十八)
1、test.yml,执行任务:安装wget,更换仓储源,获取信息等 hosts: all gather_facts: false tasks: name: yum wget yum: pkg=wget state=latest name: mv old repo shell: mv /etc/yum.
1281 0
|
机器学习/深度学习 Shell 开发工具