我已经尝试过很多次搜索,但是我找不到任何合适的解决方案。
我想使用 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 [install mongoDB] ********************************************************* fatal: [13.232.181.230]: FAILED! => {"cache_update_time": 1620583763, "cache_updated": true, "changed": false, "msg": "'/usr/bin/apt-get -y -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" install 'mongodb=4.2'' failed: E: Version '4.2' for 'mongodb' was not found\n", "rc": 100, "stderr": "E: Version '4.2' for 'mongodb' was not found\n", "stderr_lines": ["E: Version '4.2' for 'mongodb' was not found"], "stdout": "Reading package lists...\nBuilding dependency tree...\nReading state information...\n", "stdout_lines": ["Reading package lists...", "Building dependency tree...", "Reading state information..."]}
在远程机器上安装特定于版本的 MongoDB 的正确方法是什么。
最佳答案
首先感谢 Zeitounator 和 Wernfried Domscheit 求助。我很感激。
我犯了多个错误。
下面是正确的 yml 文件,它工作正常。
我正在安装
Mongo 4.4
. 4.2 的步骤将保持不变。您必须确保 key 路径和 repo 。解决方案
---
# 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
关于mongodb - 使用 Ansible 安装特定于版本的 MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67461457/