0

I have tried to search this a lot but, I am not able to find any proper solution.

I want to install MongoDB 4.2 on 3 machines using Ansible but I don't know how to specify the version.

My OS is Ubuntu Server 20.04

Below yml file is causing version error

---
# 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

Here is the error

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..."]}

What is the proper way to install version specific MongoDB on remote machines.

7
  • What is the error your get? Commented May 9, 2021 at 19:53
  • How would you specify the version if using apt on the command line directly ? Just write the name the exact same way This question has nothing to do with ansible, not either with programming at all and is therefore off-topic here. If you are still having difficulties, try superuser.com Commented May 9, 2021 at 20:03
  • @WernfriedDomscheit, I have updated the post with error message. Commented May 10, 2021 at 6:45
  • Are you able to install (outdated) Mongo 4.2 manually with apt? Commented May 10, 2021 at 6:59
  • If I try to install this manually using the Linux terminal, I can do that successfully. This time I am trying to use Ansible so I could install this on multiple machines easily. Commented May 10, 2021 at 7:04

1 Answer 1

0

First, I would like to thank Zeitounator and Wernfried Domscheit for help. I appreciate that.

I was making multiple mistakes.

  • They key was wrong
  • The repository information was missing
  • The name of the mongo installation package was wrong.
  • The mongo service check was incorrect.

Below is the correct yml file, and it's working fine.
I am installing Mongo 4.4. The steps will remain the same for 4.2. You will have to make sure the key path and repo.

Solution

---
# 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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.