一、添加主机
1 sudo vim /etc/ansible/hosts
------------------------------------------------------>
[group01] 10.0.0.26
二、创建自动化脚本
vim playbooks/akey_flask.yml
----------------------------------------------------->
--- - name: install flask hosts: group02 remote_user: root tasks: - name: install apt pakages apt: pkg={{ item }} update_cache=yes cache_valid_time=3600 //此脚本用于安装在ubuntu上 with_items: - python-pip - name: install required python pakages pip: name={{ item }} with_items: - flask - flask-wtf - sqlalchemy - name: restart ssh //此处完全可以去掉,加上去的目的只是为了测试服务启动功能 service: name=ssh state=restarted
三、运行脚本
sudo ansible-playbook akey_flask.yml
运行结果如下: