1

How do I get the bash script below to create a yum repo definition file that can successfully facilitate the installation of mongodb?

As you can see, the current version of the script is causing a failure, which you can read below.

The relevant section of the current bash script is:

echo "[STARTING TASK 4: Install MongoDB]"
echo "... About to create the repo file with a cat command ..."
cat >/etc/yum.repos.d/mongodb-org.repo <<EOL
line 1, [mongodb-org-3.4]
line 2, name=MongoDB Repository
line 3, baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
line 4, gpgcheck=1
line 5, enabled=1
line 6, gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
line 7 line
... 
EOL

echo "... About to confirm with yum repolist"
yum repolist
echo "... About to yum -y install mongodb-org"
yum -y install mongodb-org
echo "... About to systemctl start mongod"
systemctl start mongod

The console output while the script runs is:

build   18-Dec-2017 17:09:07    [STARTING TASK 4: Install MongoDB]
build   18-Dec-2017 17:09:07    ... About to create the repo file with a cat command ...
build   18-Dec-2017 17:09:07    ... About to confirm with yum repolist
build   18-Dec-2017 17:09:07    Loaded plugins: fastestmirror, langpacks
error   18-Dec-2017 17:09:07    
error   18-Dec-2017 17:09:07    
error   18-Dec-2017 17:09:07    File contains no section headers.
error   18-Dec-2017 17:09:07    file: file:///etc/yum.repos.d/mongodb-org.repo, line: 1
error   18-Dec-2017 17:09:07    'line 1, [mongodb-org-3.4]\n'
build   18-Dec-2017 17:09:07    ... About to yum -y install mongodb-org
build   18-Dec-2017 17:09:07    Loaded plugins: fastestmirror, langpacks
error   18-Dec-2017 17:09:07    
error   18-Dec-2017 17:09:07    
error   18-Dec-2017 17:09:07    File contains no section headers.
error   18-Dec-2017 17:09:07    file: file:///etc/yum.repos.d/mongodb-org.repo, line: 1
error   18-Dec-2017 17:09:07    'line 1, [mongodb-org-3.4]\n'
build   18-Dec-2017 17:09:07    ... About to systemctl start mongod
error   18-Dec-2017 17:09:07    Failed to start mongod.service: Unit not found.

As you can see, the error seems be caused by the script not being able to create a readable version of /etc/yum.repos.d/mongodb-org.repo. By contrast, I was able to use manual commands to create a working version of the file.

  • Is there a reason why you need to have "line #," at the beginning of each line? – Ignacio Vazquez-Abrams Dec 19 '17 at 1:32
  • @IgnacioVazquez-Abrams I copied them from another posting on another SE site. If I interpreted the meaning incorrectly, then I am happy to be corrected with something specific that works. – CodeMed Dec 19 '17 at 1:34
  • Have you looked at any other repo definition files? – Ignacio Vazquez-Abrams Dec 19 '17 at 1:35
  • Pretty sure the "line x" parts are extraneous and should be removed. They were probably in the original post for reference. – Jeff Schaller Dec 19 '17 at 1:35
  • ... and that extra text may be the entirety of your problem. – Jeff Schaller Dec 19 '17 at 1:36
2

I believe the shortest fix to your problem is the repo-generating code; change it to:

cat >/etc/yum.repos.d/mongodb-org.repo <<EOL
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/6Server/mongodb-‌​org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
EOL

so that the extraneous text is not printed. I don't know what was in line 7 or beyond, but continue the idea of removing the leading "line ..." text.

Not the answer you're looking for? Browse other questions tagged or ask your own question.