archlinux
1
2
| # archlinux 直接从仓库里安装就是最新版本
sudo pacman -S git ansible
|
ubuntu,debian
ubuntu 默认 apt 安装的ansible版本可能是旧版本, 建议参照ansible官网文档安装新版本的ansible
https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#latest-releases-via-apt-debian
Add the following line to /etc/apt/sources.list:
1
| deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main
|
Then run these commands:
1
2
3
| sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
sudo apt-get update
sudo apt-get install ansible
|
编写ansible 脚本
1
2
3
4
5
6
7
| vim local.yml
- hosts: localhost
become: true
tasks:
- name: Install htop
apt: name=htop
|
提交到github
1
2
3
| git add local.yml
git commit -m "initial commit"
git push origin master
|
执行脚本 ansible-pull模式
1
| sudo ansible-pull -U https://github.com/wiloon/ansible.git
|
本地执行
1
| ansible-playbook ansible/local.yml --extra-vars "user_name=wiloonwy"
|
https://linux.cn/article-10434-1.html