yname: yzt name: “”
{name:yzt}
数字/布尔/字符串
---
- hosts: 192.168.0.107
remote_user: root
vars:
touch_file: imoocc.file
tasks:
- name: touch file
shell: "touch /tmp/"
ansible-playbook -i ./hosts --list-hosts ./f1.yml
ansible-playbook -i ./hosts ./f1.yml
WARNING: Consider using the file module with state=touch rather than running ‘touch’. If you need to use command because file is insufficient you can add ‘warn: false’ to this
翻译过来就是剧本
play: 定义的是主机角色 task:定义的具体的执行角色(部署代码/安装服务) playbook: 由一个或者多个play组成,一个play可以包含多个task
macbookpro@bogon /etc/ansible tree
.
├── ansible.cfg
├── hosts
/etc/yum.repos.d
如果机器上没有git 先要安装,注意下面的执行命令要用双引号
ansible one -m git -a "repo=https://github.com/buqiucdn/buqiucdn.github.io dest=/opt/imoocc version=HEAD" -f 5 -l 192.168.0.108
192.168.0.108 | CHANGED => {
"after": "9b0f58b04bca0d266b6c633b873471229cfb2568",
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"before": "HEAD",
"changed": true,
"remote_url_changed": false
}
macbookpro@bogon /etc/ansible tree
.
├── ansible.cfg
├── hosts
/etc/yum.repos.d
ansible.cfg
macbookpro@bogon /etc/ansible tree
.
├── ansible.cfg
├── hosts
hosts是ansible自动化任务中所有的主机组
1.密码登录
192.168.0.104:22 ansible_ssh_user=playcrab ansible_ssh_pass='123456'
192.168.0.110:22 ansible_ssh_user=root ansible_ssh_pass='123123'
2.公钥登录
192.168.0.104:22 ansible_ssh_user=playcrab ansible_ssh_key_file=/Users/macbookpro/.ssh/id_rsa
192.168.0.110:22 ansible_ssh_user=root ansible_ssh_key_file=/Users/macbookpro/.ssh/id_rsa
3.公钥配置在ansible.cfg
192.168.0.104:22 ansible_ssh_user=playcrab
192.168.0.110:22 ansible_ssh_user=root