@contribute
2016-06-03T01:23:33.000000Z
字数 1255
阅读 1495
tinkerpop
ansible linshi -m copy -a "src=/root/github/mg-playbooks dest=~"
pip install ansible
pip install https://github.com/pallets/jinja/zipball/master
pip install paramiko
# 测试命令
ansible all -m ping
# 返回管理机器的一些基本信息
ansible all -m setup
ansible all -a 'date'
这是一条ad-hoc命令——临时执行命令,ad-hoc是ansible里的一个概念, 在上面命令中就是 -a ,具体稍后再说。命令中的all是值hosts中的所有服务器,当然也可以通过 ansible -i ~/hosts -a'who' 这样根据组名指定服务器。
ad-hoc
——临时的,在ansible中是指需要快速执行,并且不需要保存的命令。说白了就是执行简单的命令——一条命令。对于复杂的命令后面会说playbook。
# 文件操作
ansible all -m file -a 'path=~/hello.txt'
# 修改文件权限
ansible all -m file -a 'path=~/hello.txt mode=700'
#拷贝文件
ansible all -m copy -a "src=/tmp/hello.txt dest=~"
# 删除文件或目录
ansible machinename -m file -a 'path=/tmp/testing state=absent'
# playbook.yml
---
- hosts: local # hosts中指定
remote_user: the5fire # 如果和当前用户一样,则无需指定
tasks:
- name: whoami
copy: src=~/hosts dest=~/hosts.dest # 本地拷贝到远端
notify: # 如果copy执行完之后~/hosts.dest文件发送了变化,则执行
- clear copy # 调用handler
handlers:
- name: clear copy
shell: 'mv ~/hosts.dest hosts.del' # 假装删除
变量优先级:
roles/xxx/vars
>host_vars
>group_vars/${host}
>group_vars/all
配置的参数有:
ansible_ssh_host
ansible_ssh_port
ansible_ssh_pass
ansible_ssh_user
ansible_connection
ansible_shell_tpye
ansible_ssh_private_key_file
ansible_python_interpreter
自动化运维工具Ansible详细部署
Ansible中文权威指南
Cassandra Ansible Playbook
ansible简单学习笔记
自动化工具 ansible中文指南
ansible常用模块用法