@contribute
2016-06-03T01:23:33.000000Z
字数 1255
阅读 1629
tinkerpop
ansible linshi -m copy -a "src=/root/github/mg-playbooks dest=~"
pip install ansiblepip install https://github.com/pallets/jinja/zipball/masterpip 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: whoamicopy: src=~/hosts dest=~/hosts.dest # 本地拷贝到远端notify: # 如果copy执行完之后~/hosts.dest文件发送了变化,则执行- clear copy # 调用handlerhandlers:- name: clear copyshell: 'mv ~/hosts.dest hosts.del' # 假装删除
变量优先级:
roles/xxx/vars>host_vars>group_vars/${host}>group_vars/all
配置的参数有:
ansible_ssh_hostansible_ssh_portansible_ssh_passansible_ssh_useransible_connectionansible_shell_tpyeansible_ssh_private_key_fileansible_python_interpreter
自动化运维工具Ansible详细部署
Ansible中文权威指南
Cassandra Ansible Playbook
ansible简单学习笔记
自动化工具 ansible中文指南
ansible常用模块用法
