专业的编程技术博客社区

网站首页 > 博客文章 正文

Ubuntu系统上安装Ansible的示例(ubuntu20.04系统安装)

baijin 2024-10-21 03:36:59 博客文章 12 ℃ 0 评论

以下是在Ubuntu系统上安装Ansible的示例:

1. 更新软件包列表:

sudo apt-get update

2. 安装Ansible:

sudo apt-get install ansible

3. 验证Ansible是否已成功安装:

ansible --version

4. 配置管理主机:

- 生成SSH密钥对,用于无密码访问目标机器:

ssh-keygen -t rsa

- 将公钥复制到目标机器的authorized_keys文件中:

ssh-copy-id user@target_machine_ip

- 编辑Ansible的inventory文件(默认为/etc/ansible/hosts),添加目标机器的信息。例如:

[webservers]

192.168.0.10

192.168.0.11

192.168.0.12

5. 编写Playbook:

- 创建一个名为`nginx.yml`的文件,其中包含要在服务器上执行的任务。例如:

---

- name: Install and configure Nginx on web servers

hosts: webservers

become: yes

tasks:

- name: Install Nginx

apt:

name: nginx

state: present

update_cache: yes

- name: Start Nginx service

service:

name: nginx

state: started

enabled: yes


6. 运行Playbook:

ansible-playbook -i hosts nginx.yml

7. 验证Nginx是否已成功安装和启动:

curl http://target_machine_ip

以上是一个简单的Ansible安装部署示例,你可以根据具体需求进行修改和扩展。

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表