编写一个简单的playbook,实现在所有被控节点上循环安装php和 mariadb服务, 在被控节点node1上面组安装Development Tools组包,更新被控节点node1上面的所有软件包
时间: 2024-02-03 09:14:51 浏览: 28
下面是一个简单的Ansible playbook,实现了在所有被控节点上安装php和mariadb服务,并在被控节点node1上安装Development Tools组包并更新所有软件包:
```yaml
- name: Install PHP and MariaDB on all nodes
hosts: all
become: true
tasks:
- name: Install PHP
yum:
name: php
state: present
- name: Install MariaDB
yum:
name: mariadb-server
state: present
- name: Install Development Tools and update software on node1
hosts: node1
become: true
tasks:
- name: Install Development Tools
yum:
name: "@Development Tools"
state: present
- name: Update all software packages
yum:
name: '*'
state: latest
```
你可以将上面的代码保存为一个YAML文件(例如`install.yml`),然后使用以下命令运行playbook:
```
ansible-playbook install.yml
```
请注意,如果您的服务器没有安装Ansible,则需要先安装Ansible。您还需要在Ansible中配置您的主机和SSH访问。
阅读全文