centos8 ansible
时间: 2023-09-12 14:10:15 浏览: 45
CentOS 8 is a Linux distribution that can be managed using Ansible, an open-source automation tool. Ansible can be used to perform various tasks such as deploying software, configuring servers, and managing infrastructure.
To use Ansible with CentOS 8, you will first need to install Ansible on your system. You can do this by running the following command:
```
sudo dnf install ansible
```
Once Ansible is installed, you can create an inventory file that lists the hosts you want to manage with Ansible. For example, you can create a file called `hosts.ini` with the following contents:
```
[web_servers]
web1.example.com
web2.example.com
[database_servers]
db1.example.com
```
This inventory file defines two groups of servers: `web_servers` and `database_servers`. You can then create a playbook that defines the tasks you want to perform on these servers. For example, you can create a playbook called `deploy_website.yml` with the following contents:
```
- name: Deploy website
hosts: web_servers
become: true
tasks:
- name: Install Apache web server
yum:
name: httpd
state: present
- name: Copy website files
copy:
src: /path/to/website/files
dest: /var/www/html
- name: Start Apache web server
service:
name: httpd
state: started
```
This playbook installs the Apache web server, copies website files to the server, and starts the web server. You can run this playbook on the servers defined in the `web_servers` group by running the following command:
```
ansible-playbook -i hosts.ini deploy_website.yml
```
This is just a basic example of how Ansible can be used with CentOS 8. Ansible offers many more features and capabilities that allow you to manage your infrastructure more efficiently and effectively.