mongodb - 使用 Ansible 安装特定于版本的 MongoDB

标签 mongodb ubuntu ansible yaml

我已经尝试过很多次搜索,但是我找不到任何合适的解决方案。
我想使用 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 求助。我很感激。
我犯了多个错误。

  • 他们的 key 错了
  • 缺少存储库信息
  • mongo安装包名称错误。
  • mongo 服务检查不正确。

  • 下面是正确的 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/

    相关文章:

    node.js - 使用PM2运行完整的开发环境

    list - E : Malformed entry 1 in list file/etc/apt/sources. list.d/docker.list(URI解析),E:无法读取源列表

    ubuntu - 替换 grep 找到的字符串

    linux - 日期 : extra operand '+%s'

    ansible - 如何在 Ansible 中向文件末尾添加一个空行?

    ansible - 从复杂的字典/列表注册变量中提取字段/值

    mongodb - 无法将数组从 MongoDB 传递到需要向量的 Spark 机器学习函数

    python - pymongo 中的快速或批量更新

    node.js - MongoDB - 找到至少一个数组值丢失的地方

    scripting - 在ansible中展平和过滤复杂的结构 - 字典列表的字典