ansible安装一个rpm包的playbook
时间: 2023-08-14 22:04:10 浏览: 187
好的,以下是一个安装RPM包的ansible playbook示例:
```yaml
---
- name: Install RPM Package
hosts: rpm_install_server
become: true
vars:
package_name: "example"
package_version: "1.0"
tasks:
- name: Install Package
yum:
name: "/path/to/{{ package_name }}-{{ package_version }}.rpm"
state: present
```
请注意,此示例需要以下条件:
- `rpm_install_server`是要安装RPM包的主机。
- `/path/to/`是RPM包的路径,你需要根据你的具体情况调整这个路径。
- `package_name`和`package_version`是你要安装的RPM包的名称和版本。你需要根据你的具体情况调整这些变量。
希望这可以帮助你编写一个 ansible playbook 来安装 RPM 包。
相关问题
ansible 编译一个rpm包的playbook
好的,以下是一个编译rpm包的ansible playbook示例:
```yaml
---
- name: Compile RPM Package
hosts: rpm_build_server
become: true
vars:
package_name: "example"
package_version: "1.0"
package_release: "1"
package_source: "https://github.com/example/example/archive/master.zip"
tasks:
- name: Install Dependencies
yum:
name:
- rpm-build
- rpmdevtools
- rpmlint
state: present
- name: Download Source Code
get_url:
url: "{{ package_source }}"
dest: "/tmp/{{ package_name }}-{{ package_version }}.zip"
- name: Extract Source Code
unarchive:
src: "/tmp/{{ package_name }}-{{ package_version }}.zip"
dest: "/tmp/{{ package_name }}-{{ package_version }}"
remote_src: true
extra_opts: [--strip-components=1]
- name: Create RPM Build Directory
file:
path: "/root/rpmbuild"
state: directory
- name: Create RPM Build Environment
command: "rpmdev-setuptree"
- name: Copy Source Code to RPM Build Directory
copy:
src: "/tmp/{{ package_name }}-{{ package_version }}"
dest: "/root/rpmbuild/SOURCES/{{ package_name }}-{{ package_version }}"
- name: Create RPM Spec File
template:
src: "example.spec.j2"
dest: "/root/rpmbuild/SPECS/{{ package_name }}.spec"
- name: Build RPM Package
command: "rpmbuild -ba /root/rpmbuild/SPECS/{{ package_name }}.spec"
```
请注意,此示例需要以下条件:
- `rpm_build_server`是可以编译RPM包的主机。
- `example.spec.j2`是一个Jinja2模板,用于生成RPM spec文件。你需要创建这个文件。
- `package_name`,`package_version`和`package_source`是你要编译的RPM包的名称,版本和源代码链接。你需要根据你的具体情况调整这些变量。
希望这可以帮助你编写一个 ansible playbook 来编译 RPM 包。
ansible 从远程主机安装rpm包
可以使用Ansible的yum模块来从远程主机安装rpm包,具体步骤如下:
1. 在Ansible的inventory文件中定义需要安装rpm包的远程主机。
2. 创建一个playbook,使用yum模块来安装rpm包,示例代码如下:
```
- hosts: remote_servers
become: yes
tasks:
- name: Install RPM package
yum:
name: /path/to/package.rpm
state: present
```
在上述代码中,remote_servers是需要安装rpm包的远程主机,/path/to/package.rpm是rpm包的路径,become: yes用于提升权限。
3. 运行playbook,执行命令:
```
ansible-playbook -i inventory_file install_rpm.yml
```
其中,inventory_file是你的inventory文件名,install_rpm.yml是你创建的playbook文件名。
执行完毕后,Ansible会在remote_servers主机上安装指定的rpm包。
阅读全文