Guide
ansible
https://linuxhandbook.com/ansible-ad-hoc/
ssh免密登录
最好使用常用镜像,alpine会出现各种错误
列出所有host
找出所有
区分环境
找出prod
执行简单命令
使用 playbooks
playbook.yml
- name: first play
hosts: all
tasks:
- name: create a new file
file:
path: /tmp/foo.conf
mode: 0664
owner: root
state: touch
ansible-playbook -i inventory.ini playbook.yml
ansible all -i inventory.ini -m command -a "ls -l /tmp/foo.conf"
# 检查语法
ansible-playbook -i inventory.ini --syntax-check playbook.yml
# 检查机器
ansible-playbook -i inventory.ini --check playbook.yml
单独指定机器
playbook.yml
- name: first play
hosts: all
tasks:
- name: install tmux
package:
name: tmux
state: present
- name: create an archive
archive:
path: /var/log
dest: /tmp/logs.tar.gz
format: gz
- name: second play
hosts: 10.0.2.9
tasks:
- name: install git
apt:
name: git
state: present
指定tag --tags git
仅执行tags任务