ansible模块应用
安装ansible
yum install ansible -y
添加主机组
vim /etc/ansible/hosts
[web]
192.168.1.1 ansible_ssh_user=root ansible_ssh_pass=password ansible_ssh_port=22
创建免密钥
vim push.ssh.yml
---
- hosts: contabo_vps1
user: root
tasks:
- name: ssh-key-copy
authorized_key: user=root key="{{ lookup('file','/root/.ssh/id_rsa.pub')}}"
tags:
- sshkey
ssh免密钥推送
ansible-playbook push.ssh.yml
在客户端创建目录
ansible web -m command -a 'chdir=/home/evz/ mkdir -p sh'
推送脚本到客户端
ansible web -m copy -a 'src=/home/evz/ansible/1.sh dest=/home/evz/sh/ mode=755'
添加定时任务
ansible web -m cron -a "minute=* hour=* day=* month=* weekday=* name='xxxxxx' job='/bin/bash /home/evz/sh/xxx.sh > /dev/null 2>&1'"
yum模块使用
ansible web -m yum -a "name=dos2unix state=installed"
windows文件转换unix格式
ansible web -m command -a 'dos2unix /home/evz/xxxx.sh'

浙公网安备 33010602011771号