要使用Ansible循环安装apache2,sqlite3和git,可以使用以下方法:
创建一个Ansible playbook文件,比如install_packages.yml。
在playbook文件中定义一个主机组,比如servers,包含要安装软件的服务器。
---
- name: Install packages using Ansible loop
hosts: servers
become: true
tasks:
- name: Install Apache2
apt:
name: apache2
state: present
- name: Install SQLite3
apt:
name: sqlite3
state: present
- name: Install Git
apt:
name: git
state: present
[servers]
server1 ansible_host=192.168.0.1
server2 ansible_host=192.168.0.2
ansible-playbook -i /etc/ansible/hosts install_packages.yml
这将在服务器组中的所有服务器上使用Ansible循环安装Apache2,SQLite3和Git软件包。