I am in process of automating installation of sage through ansible-playbook. In that I need to run two shell scripts.
Here is how the first shell script look:
#!/bin/bash
# Creating Sage notebook
dir="/root/.sage/sage_notebook.sagenb"
screen -S "Sage_Server" sage -c 'notebook(interface="", directory=$dir, port=80, accounts=true)'
This is the second shell script's code:
#!/bin/bash
# Creating Sage inotebook
address=$(hostname --ip-address)
sage -c "inotebook(interface=" "'$address'" ",port=80,accounts=true)"
And this is how the playbook looks:
---
- hosts: localhost
remote_user: root
tasks:
- name : update system
apt : update_cache=yes
- name : install m4
apt : name=m4 state=present
- name : install build-essential
apt : name=build-essential state=present
- name : install gcc
apt : name=gcc state=present
- name : install gfortran
apt : name=gfortran state=present
- name : install libssl-dev
apt : name=libssl-dev state=present
- name : install python-software-properties
apt : name=python-software-properties state=present
- name : add sage ppa repo
apt_repository: repo='ppa:aims/sagemath'
- name : update system
apt : update_cache=yes
- name : install dvipng
apt : name=dvipng state=present
- name : install sage binary
apt : name=sagemath-upstream-binary state=present
- name : invoke create_sagenb script
command: /usr/bin/screen -d -m sudo /root/databases-and-datamining-iiith/python-scripts/create_sagenb -i -y
- name : invoke start_sage script
command: /usr/bin/screen -d -m sudo /root/databases-and-datamining-iiith/python-scripts/start_sage -i -y
Now when I run the first script, it asks for a new sage password which could be anything. But I am not able to pass that password from the playbook.
Still, if I do
ps -ef | grep sh
I could see that the scripts are running but the sage service is not running.
It needs the password in order to start the service.
Could anyone please tell me how can I provide password as an argument to the shell scripts through command.
I don't know sage and don't know how to provide a password in an alternative way, but if the program ask for a password than you can probably use expect as suggested here.
As a rule of thumb you shouldn't run scripts that needs user input in ansible playbooks.
You could try to use something like
echo "password" | script.sh
or
Create a sage-password file in /etc containing the password and:
script.sh < /etc/sage-password
But this will only work if it is reading from stdin - most applications read password directly from terminal device driver (i.e. /dev/ttyS# ), in that case this trick won't work.
If that's the case, take a look to the sage docs, they should have a more robust way for non-interactive startup.
Related
I am trying to RUN sudo su - inside the Dockerfile and I get this error
/bin/sh: 1: sudo: not found
This is how my Dockerfile looks like:
FROM ubuntu:18.04
RUN sudo su -
RUN apt update && install openjdk-8-jdk
RUN wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add - && sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/kenkins.list'
RUN apt update && apt install jenkins
RUN curl -fsSL get.docker.com | /bin/bash
RUN usermod -aG docker jenkins && systemctl restart jenkins
This error comes when I try to build it.
docker build -t jenkins .
Can someone help me?
The dockerfile will run as a virtual "root" user by default, so there is no need to include any sudo command.
Since the example script contains no "-y" defaults it seems that you have simply typed the description for a manual installation into a script. This will never work. And well, in a container the application does also need to be on PID-1 which systemctl will not do.
After going through a basic tutorial on docker you will find out why.
This command seems not to be doing anything except for creating an extra layer without any useful effect.
$ cat Dockerfile
FROM ubuntu:18.04
RUN apt-get update && apt-get install openjdk-8-jdk -y
If You want to change the use privilege use USER flag in Dockerfile
I am trying to install puppet5 on a Virtual-box CentOS-6.9.(Master)
I have typed the following commands:
iptables -F
service iptables save
rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm
yum install puppet-server
puppet resource package puppet-server ensure=latest
Eventually when I type: puppet --version
I get 3.8.7.
How can i get puppet version 5?
Am I missing something?
Thanks
Oz
Puppet 3, 4 and 5 all use different upstream yum repositories to avoid accidental upgrades to an incompatible version.
If you want to install Puppet 5 on a EL6 machine, you will want to do the following:
rpm -ivh http://yum.puppetlabs.com/puppet5/puppet5-release-el-6.noarch.rpm
yum install puppet-agent -y
Or you can use my all in one script:
https://github.com/petems/puppet-install-shell
Puppet 3.8.X
$ wget -O - https://raw.githubusercontent.com/petems/puppet-install-shell/master/install_puppet.sh | sudo sh
Puppet 4
$ wget -O - https://raw.githubusercontent.com/petems/puppet-install-shell/master/install_puppet_agent.sh | sudo sh
Puppet 5
$ wget -O - https://raw.githubusercontent.com/petems/puppet-install-shell/master/install_puppet_5_agent.sh | sudo sh
To install Puppet5 in CentOS-7 (VM), I followed the following steps:
1) Login to your VM and go root
sudo su -
2) Copy the Puppet5 link address from yum.puppetlabs.com according to your system architecture
rpm -ihv https://yum.puppetlabs.com/puppet5/puppet5-release-el-7.noarch.rpm
3) Install Puppet server
yum -y install puppetserver
4) Now if your check puppet version (puppet --version), it will show you error -> -bash: puppet: command not found.
This is because Puppet is defined in two different paths:
/opt/puppetlabs/bin and /opt/puppetlabs/puppet/bin
To resolve this, you need to add the binary in puppet-agent.sh:
vi /etc/profile.d/puppet-agent.sh
5) Edit file puppet-agent.sh
# Add /opt/puppetlabs/bin to the path for sh compatible users
if ! echo $PATH | grep -q /opt/puppetlabs/bin ; then
export PATH=$PATH:/opt/puppetlabs/bin
export PATH=$PATH:/opt/puppetlabs/puppet/bin
fi
6) logout and login again as root:
logout
sudo su -
7) Check Puppet Version
puppet --version
I am a newbie with server handling and Linux. I am trying to install composer on my server so that i can host my Laravel project onto it as mentioned in the tutorial in Ultimate Guide: Deploy Laravel 5.3 App on LEMP Stack. I ssh into the server and after installation of composer when I run sudo mv composer.phar /usr/local/bin/composer I am getting a message in the terminal:
-bash: sudo: command not found
I desperately need some deliberate help
Sudo is probably not installed or not in your path
check to see if you are root in this case sudo is not needed unless you are trying to impersonate another user. just run your command without sudo mv composer.phar /usr/local/bin/composer
See if sudo is your path by running which sudo or echo $PATH. If sudo is not in your path, your path variable might be broken. You can try testing this by executing a common location for sudo /usr/bin/sudo or running locate sudo | grep bin to attempt to find its location.
If you know that sudo was installed, or your path looks broken, try fixing your path. Check your distribution's env file (/etc/environment in ubuntu) to make sure that it is formatted correctly (script commands are illegal in this file)
If you are not root and you want to run a command with root prvileges then you must install sudo. But if you don't have sudo and you are not root then you can't install it. In this case I recommend switching to the root user with su
If you do not have the root password and you own the machine, you can reset the root password with a tutorial such as https://askubuntu.com/questions/24006/how-do-i-reset-a-lost-administrative-password
After you manage to login as root install sudo with apt-get update; apt-get install sudosince you are using Ubuntu.
Verify the the name of your sudoers group with visudo and modify your sudoers file if you need to. https://www.digitalocean.com/community/tutorials/how-to-edit-the-sudoers-file-on-ubuntu-and-centos
if you have an existing sudoers group or you create one you can add yourself to the group. For example if your sudoers group is called sudo run usermod -aG sudo myuser. The sudoers group by default in Ubuntu based Linux is sudo. A sudoers group entry looks like this: %sudo ALL=(ALL:ALL) ALL
If you are trying to impersonate another user and cannot install sudo, you can still use su if it is installed and you have permission / password for the other user.
e.g. su someuser
As suggested in this post, you may have to install sudo in your server.
To do that, log in as root with the following command: su -. Then install sudo with your package manager (if you're in Ubuntu: apt-get install sudo).
Then add your user to the sudo group: usermod -aG sudo <username>.
Finally type exit to log out of the root account and go back to your user.
try to install your sudo using by first logging in as a root(su - ) and then try to install **apt-get or yum sudo **. Make sure your path variable is set so that you would be able to get binary.
which sudo
echo $PATH
I am working on Ansible playbook to execute some of my tasks. In one of my tasks, I need to switch to particular directory and then execute a command using sudo but I need to do all these things by switching to root user first otherwise it won't work. So in general this is what I do without ansible:
david#machineA:/tmp/parallel-20140422$ sudo su
root#machineA:/tmp/parallel-20140422# sudo ./configure && make && make install
After above steps, I see GNU parallel library is installed in my system correctly. But with the below steps using Ansible, I don't see my GNU library getting installed at all.
- name: install gnu parallel
command: chdir=/tmp/parallel-20140422 sudo ./configure && make && make install
Now my question is how can I switch to root user and execute a particular command. I am running Ansible 1.5.4 and looks like I cannot upgrade. I even tried with below but still it doesn't work:
- name: install gnu parallel
command: chdir=/tmp/parallel-20140422 sudo ./configure && make && make install
sudo: true
sudo_user: root
I am running my playbook using below command:
ansible-playbook -e 'host_key_checking=False' setup.yml -u david --ask-pass --sudo -U root --ask-sudo-pass
You need the become directive.
For example, to start a service as root:
- name: Ensure the httpd service is running
service:
name: httpd
state: started
become: true
you can also become another user, such as the apache user:
- name: Run a command as the apache user
command: somecommand
become: true
become_user: apache
For your case, it will be:
- name: install gnu parallel
command: chdir=/tmp/parallel-20140422 sudo ./configure && make && make install
become: true
From your comment:
I know command module is working fine bcoz I verified for other tasks and they work fine.
command module might be working for other commands, but in this example you use a shell syntax (&&) to execute multiple commands. This syntax will not work in the command module (because this module runs commands directly from Python and does not support combined commands).
You need to use the shell module in this case.
- name: install gnu parallel
shell: ./configure && make && make install
args:
chdir=/tmp/parallel-20140422
sudo: true
sudo_user: root
I am trying run a specific version of couchdb on travis-ci I do this by following the offical apt-get instructions from couchdb
Part of the installation is a prompt for what to do with an old configuration file. See the following:
Installing new version of config file /etc/logrotate.d/couchdb ...
Configuration file `/etc/couchdb/local.ini'
==> Deleted (by you or by a script) since installation.
==> Package distributor has shipped an updated version.
What would you like to do about it ? Your options are:
Y or I : install the package maintainer's version
N or O : keep your currently-installed version
D : show the differences between the versions
Z : start a shell to examine the situation
The default action is to keep your current version.
*** local.ini (Y/I/N/O/D/Z) [default=N] ?
This causes travis-ci to hang and the build to fail.
Here is the travis-ci i have tried with and without the sudo rm and a handful of otherthings.
language: python
php:
- 2.7
install: "pip install -r requirements.txt"
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sudo apt-get install python-software-properties -y
- sudo add-apt-repository ppa:couchdb/stable -y
- sudo apt-get update -yq
- sudo apt-get remove couchdb couchdb-bin couchdb-common -yf
- sudo rm /etc/couchdb/local.ini
- sudo apt-get install -Vy couchdb
- sudo service couchdb start
before_script:
- curl -X PUT localhost:5984/njb_tests
script: python run-tests.py
You can see the different things i have tried by looking at my commit history:
https://github.com/Victory/notice-javascript-bugs/commits/master/.travis.yml
Hello my Frind its quite easy
I believe this command will do the trick
The 100% Working way no excuse no mercy!!
sudo DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" install couchdb
The Softer way probally working
export DEBIAN_FRONTEND=noninteractive
apt-get -o Dpkg::Options::="--force-confnew" install -y
The Right way
on shell or in code do
export DEBIAN_FRONTEND=noninteractive
then
sudo apt-get -q -y install couchdb
It will assume “yes” to everything (and do it quietly)
you need to watch Debconf is the name of the tool. That page should help you get going with everything you want to know. debconf man page
The expect script method
you get asked for package maintainer or a password you should set on apt-get do here a simple example from a server that asks to set password on apt-get install
To keep your existing password, leave this blank.
Password for SYSDBA:
then you run it with this script below to do the input
#!/usr/bin/expect
spawn dpkg-reconfigure firebird2.5-superclassic -freadline
expect "Enable Firebird server?"
send "Y\r"
expect "Password for SYSDBA:"
send "newpwd\r"
# done
expect eof
Working example for your case is
- /usr/bin/expect 'spawn sudo apt-get install -Vy couchdb \n expect "*** local.ini (Y/I/N/O/D/Z) [default=N] ?" \n send "Y\r"