args must be a dictionary error while using ansible - linux

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 am getting an error:
- name: install gnu parallel
shell: ./configure && make && make install
args:
chdir=/tmp/parallel-20140422
sudo: true
sudo_user: root
Below is the error I am getting:
fatal: [machineA] => args must be a dictionary, received chdir=/tmp/parallel-20140422
I am working with 1.5.4 ansible. I am not sure what's wrong here with my ansible tasks?

Your task should probably look like this:
- name: install gnu parallel
shell: ./configure && make && make install
args:
chdir: /tmp/parallel-20140422
sudo: true
sudo_user: root
I'm a bit confused that you have to give root as sudo_user, because that's the default as far as I know. But then again, if it works for you, it works.

Related

As part of shell script, sudo su is not working. Any alternate?

The below 3 lines are part of my shell script, but it is executing first line and copying file properly.
In-order execute this rpm file, i need to prompt to root user. Hence, 2nd step i wrote. But it is not executing, hence i'm not able to install the rpm file.
aws s3 cp s3://mybucket/oracle-instantclient12.2-basiclite.rpm /home/user1/
sudo su
yum -y install /home/user1/oracle-instantclient12.2-basiclite.rpm
So, any alternate solution to this (sudo su) or tell me how to prompt to root user in-order to install the mentioned rpm file.
Thanks
You could try using sudo -s or
sudo yum -y install /home/user1/oracle-instantclient12.2-basiclite-12.2.0.1.0-1.x86_64.rpm
The first option switches you to the root user, while the second allows you to run the command as root.
aws s3 cp s3://mybucket/oracle-instantclient12.2-basiclite.rpm /home/user1/ && sudo -i yum -y install /home/user1/oracle-instantclient12.2-basiclite.rpm
you'd have to add && (see this answer) in between the two commands and install with sudo yum:
aws s3 cp s3://mybucket/oracle-instantclient12.2-basiclite.rpm /home/user1/ && sudo yum -y install /home/user1/oracle-instantclient12.2-basiclite.rpm
sudo rpm -i /home/user1/oracle-instantclient12.2-basiclite.rpm should also work.
there is no other way to run two commands from a single command-line ...
are you sure the seconds half of the command-line even runs on the remote host? because I'd rather would expect it to be prefixed with send-command (in case running this from a local shell and not on the remote host). it is also not being indicated which Linux distribution you attempt to run the command against; adding the relevant RPM repository and then installing from there, might be the most reliable method of doing so.

execute a command by switching to root user in ansible

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

can't install nvm on linux 14.04

I just fired up a new EC2 instance on Amazon and I'm trying to install nvm. I tried running their install script with the NVM_DIR=... for a global install:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | NVM_DIR=/usr/local/nvm bash
but I get this error:
=> Downloading nvm from git to '/usr/local/nvm'
=> mkdir: cannot create directory ‘/usr/local/nvm’: Permission denied
I get this error with sudo as well. I also tried going into usr/local and making the nvm directory manually, but then i get other errors like this:
=> Cloning into '/usr/local/nvm'...
/usr/local/nvm/.git: Permission denied
Does anyone know why this is happening? Is it a permissions thing on aws I am unfamiliar with?
Edit: using a much older version without the NVM_DIR stuff worked. I still want global access though, so this does not solve the problem
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.1/install.sh | sh
Your normal user won’t have access to write to /usr/local, so you’ll need to run the install script as root/sudo.
Your curl command is fine to run as your user. In fact, it’s best to just curl the file to a local location before running it, so you can eyeball it -- unless you have reason to believe it is a very trustworthy script. So grab the install.sh script:
% curl -O https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh
% $EDITOR install.sh # feel free to look it over
Then install it with sudo:
% sudo -i # become root temporarily
# export NVM_DIR=/usr/local/nvm # set the environment variable
# bash install.sh # run installer as root
# exit
%
(There is a way to make the whole installation a one-liner, passing the environment variable through sudo, but I don't think it's necessary, and a little more complex, IMHO.)

how to set supervisor to run a shell script

Setting up a Dockerfile to install node prereqs and then set up supervisor in order to run the final npm install command. Running Docker in CoreOS under VirtualBox.
I have a Dockerfile that sets everything up correctly:
FROM ubuntu
MAINTAINER <<Me>>
# Install docker basics
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y
# Install dependencies and nodejs
RUN apt-get update
RUN apt-get install -y python-software-properties python g++ make
RUN add-apt-repository ppa:chris-lea/node.js
RUN apt-get update
RUN apt-get install -y nodejs
# Install git
RUN apt-get install -y git
# Install supervisor
RUN apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor
# Add supervisor config file
ADD ./etc/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Bundle app source
ADD . /src
# create supervisord user
RUN /usr/sbin/useradd --create-home --home-dir /usr/local/nonroot --shell /bin/bash nonroot
RUN chown -R nonroot: /src
# set install script to executable
RUN /bin/chmod +x /src/etc/install.sh
#set up .env file
RUN echo "NODE_ENV=development\nPORT=5000\nRIAK_SERVERS={SERVER}" > /src/.env
#expose the correct port
EXPOSE 5000
# start supervisord when container launches
CMD ["/usr/bin/supervisord"]
And then I want to set up supervisord to launch one of a few possible processes, including an installation shell script that I've confirmed to work correctly, install.sh, which is located in the application's /etc directory:
#!/bin/bash
cd /src; npm install
export PATH=$PATH:node_modules/.bin
However, I'm very new to supervisor syntax, and I can't get it to launch the shell script correctly. This is what I have in my supervisord.conf file:
[supervisord]
nodaemon=true
[program:install]
command=install.sh
directory=/src/etc/
user=nonroot
When I run the Dockerfile, everything runs correctly, but when I launch the image, I get the following:
2014-03-15 07:39:56,854 CRIT Supervisor running as root (no user in config file)
2014-03-15 07:39:56,856 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
2014-03-15 07:39:56,913 INFO RPC interface 'supervisor' initialized
2014-03-15 07:39:56,913 WARN cElementTree not installed, using slower XML parser for XML-RPC
2014-03-15 07:39:56,914 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-03-15 07:39:56,915 INFO supervisord started with pid 1
2014-03-15 07:39:57,918 INFO spawnerr: can't find command 'install.sh'
2014-03-15 07:39:58,920 INFO spawnerr: can't find command 'install.sh'
Clearly, I have not set up supervisor correctly to run this shell script -- is there part of the syntax that I'm screwing up?
The best way that I found was setting this:
[program:my-program-name]
command = /path/to/my/command.sh
startsecs = 0
autorestart = false
startretries = 1
think I got this sorted: needed the full path in command, and instead of having user=nonroot in the .conf file, I put su nonroot into the install.sh script.
I had a quick look in the source code for supervisor and noticed that if the command does not contain a forward slash /, it will look in the PATH environmental variable for that file. This imitates the behaviour of execution via shell.
The following methods should fix your initial problem:
Specify the full path of the script (like you have done in your own answer)
Prefix the command with ./, i.e. ./install.sh (in theory, but untested)
Prefix the command with the shell executable, i.e. /bin/bash install.sh
I do not understand why user= does not work for you (have you tried it after fixing execution?), but the problem you encountered in your own answer was probably due to the incorrect usage of su which does not work like sudo. su will create its own interactive shell and will therefore hang while waiting for standard input. To run commands with su, use the -c flag, i.e. su -c "some-program" nonroot. An explicit shell can also be specified with the -s flag if necessary.
I had this issue too. For me, the root cause was failing to set the shebang line. Even if the script can run in bash fine, for supervisord to be able to exec() it, it has to begin with e.g. #!/bin/bash.

Jenkins failed to start in linux

go to run jenkins after doing an upgrade, and get the following:
start jenkins
start: Job failed to start
That's it...nothing shows up in jenkin's log...so it is difficult to debug to say the least.
(and it isn't running already, or anything like that).
Is there another log somewhere that I should be looking at that would be helpful?
(I am assuming answer to this problem will be somewhat iterative, so hopefully someone can start me on a path to debug this)
So, knowing it was a pre-start error allowed me to investigate more deeply.
Further digging allowed me to figure out that the exact line in the /etc/init/jenkins.conf file was one pointing to the /usr/share/jenkins/bin/maintain-plugins.sh
Looking at this location, I found it was not present (ie. no bin directory). This means that jenkins-common was no longer installed for some reason...odd indeed...going into apt-get and doing an install of this component again led to the error:
dpkg error processing /var/cache/apt/archives/jenkins-common_1.409.1-0ubuntu4.2_all.deb ...
having seen this error before and refreshing my memory via google gave the following solution:
dpkg -i --force-overwrite /var/cache/apt/archives/jenkins-common_1.409.1-0ubuntu4.2_all.deb
This allowed the installation of common to proceed as normal. After this, all I had to do was replace the /usr/share/jenkins/jenkins.war with my backed up copy (because ubuntu is far behind the latest release version), and I was able to start the server again.
I am not exactly sure what caused the problem to begin with, but it was likely during an apt-get upgrade/clean process...and because of the weirdness with jenkins conflicting with jenkins-common, it did not repopulate the /usr/share/jenkins directory properly.
regardless, am glad it is working again. :)
Instead, you can run the following before the install to properly clean up any conffiles left by the distro version:
sudo apt-get purge jenkins
Then install the correct version.
Ubuntu 18.04 LTS use Java 9 as default java
Jenkins 2.107.2 still use Java 8
[Solution]
Install Java 8 before install Jenkins
sudo add-apt-repository ppa:webupd8team/java
sudo apt install oracle-java8-installer
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo apt-add-repository "deb https://pkg.jenkins.io/debian-stable binary/"
sudo apt install jenkins
See https://stackoverflow.com/a/49937744/900684
I went to see the jenkins logs
tail -f /var/log/jenkins/jenkins.log
In my case it didn't start because I used incompatible java version.
Update and make sure it sees correct java (In my case it should have been opened using JRE 1.7. To check, please use java -version command) and all should work
The following worked for me:
sudo rm /etc/init/jenkins.conf
sudo update-rc.d jenkins defaults
sudo service jenkins start
Then....
root#core:/# service jenkins start
* Starting Jenkins Continuous Integration Server jenkins [ OK ]
Borrowed from: https://groups.google.com/forum/#!msg/jenkinsci-users/eW_yEWLojFc/tFhb8DKoRHUJ
I got from this link: https://serverfault.com/questions/710680/jenkins-not-starting-in-ubuntu
It might be caused by a full disk.
To be really sure, try running it manually. Like this:
/usr/bin/java -Djava.awt.headless=true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080 --ajp13Port=-1

Resources