使用Ansible安装特定版本的MongoDB



我已经尝试过多次搜索,但找不到任何合适的解决方案。

我想使用Ansible在3台机器上安装MongoDB 4.2,但我不知道如何指定版本。

我的操作系统是Ubuntu服务器20.04

以下yml文件导致版本错误

---
# tasks file for mongoDB setup
- hosts: ec2
become: true

tasks:
- name: Install aptitude using apt
apt: 
name: aptitude 
state: latest 
update_cache: yes  

- name: install mongoDB
apt: 
name: mongodb=4.2
state: present
update_cache: yes
- name: Ensure mongodb is running and and enabled to start automatically on reboots
systemd:
name: mongodb
enabled: yes
state: started

这是错误

TASK〔安装mongoDB〕*********************************************************致命:[13.281.230]:失败=>{"cache_update_time":1620583763,"cache_updated":真,";"更改":false;msg":"'/usr/bin/apt-get-y-o";Dpkg::选项::=--force confdef&quot-o";Dpkg::选项::=--force-confold"安装"mongodb=4.2"失败:E:找不到"mongodb"的版本"4.2"\n"rc":100,"stderr":"E: 找不到"mongodb"的版本"4.2";,"stderr_lines":["E:找不到'mongodb'的版本'4.2'"],"stdout":"正在读取程序包列表。。。\n构建依赖关系树\正在读取状态信息。。。\n〃"stdout_lines":[阅读程序包列表&"正在生成依赖关系树&"正在读取状态信息"]}

在远程机器上安装特定版本的MongoDB的正确方法是什么。

首先,我要感谢ZeitounatorWernfried Domscheit的帮助。我很感激。

我犯了很多错误。

  • 他们的钥匙错了
  • 存储库信息丢失
  • mongo安装程序包的名称错误
  • mongo服务检查不正确

下面是正确的yml文件,运行良好
我正在安装Mongo 4.4。4.2的步骤将保持不变。您必须确保密钥路径和回购。

解决方案

---
# tasks file for mongoDB setup
- hosts: ec2
become: true

tasks:
- name: Install aptitude using apt
apt: 
name: aptitude 
state: latest 
update_cache: yes 

- name: Import public key
apt_key:
url: 'https://www.mongodb.org/static/pgp/server-4.4.asc'
state: present

- name: Add repository
apt_repository:
filename: '/etc/apt/sources.list.d/mongodb-org-4.4.list'
repo: 'deb https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse'
state: present
update_cache: yes

- name: Install mongoDB
apt: 
name: mongodb-org
state: present
update_cache: yes
- name: Ensure mongodb is running and and enabled to start automatically on reboots
service: 
name: mongod 
enabled: yes
state: started

最新更新