in playbooks each task can set variables using the environment: var=val, keyword, but I don't think there is currently no way to do this for the ansible 1 liner.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
# the default sudo executable. If a sudo alternative with a sudo-compatible interface# is used, specify its executable name as the default#sudo_exe=sudosudo_exe=/usr/local/bin/sudo
# the default flags passed to sudo# sudo_flags=-H
xqa1prxy2$ sudo su - cqadm
"Instead of breaking right away, I ended up leaving for tea and found out it's hanging because it's expecting inputs."--ask-sudo-pass may be your friend here.
$ ansible --versionansible 1.4 (devel 18b6372c63) last updated 2013/11/21 15:05:57 (GMT -700)
sudo su - [login]
sudo su [login]
sudo -u ldapadm '[command]'
metan@xqa1prxy1$ sudo -u ldapadm 'ls'Password:metan@xqa1prxy1$ sudo su ldapadmPassword:metan@xqa1prxy1$ sudo su - ldapadmldapadm@xqa1prxy1$
$ ansible --verbose -i /app/scripts/webadm/ansible/customer-portal/hosts proxy -a "sudo su - ldapadm"xqa1prxy2 | FAILED | rc=2 >>[Errno 2] No such file or directoryxqa1prxy1 | FAILED | rc=2 >>[Errno 2] No such file or directory
What OS are you running from?
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
"But target hosts are Solaris 10 on x86 with Python 2.6"
Sounds like that's it, you just didn't have sudo in path.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
As indicated, this isn't about setting the path, this is about configuring sudo in ansible.cfg to include the full path to the sudo executable.This is the way this will need to be done as this all happens before executing the module, hence using Ansible to set a path is not possible.
#sudo_exe=sudosudo_exe=/usr/local/bin/sudo
ssh [hostname] "sudo -u [username] '[command]'"
Melissa,I have this same situation and ansible's default setup of not using a user's login shell caught me off-guard at first to. It makes sense though for Ansible **not** to want to load the user's environment in order to ensure a consistent shell experience for all modules (especially if a user has zsh as their default for example).The solution I had to use goes against best practices but I'm in the same boat as you where I can't change how sudo is setup on my systems as they are dictated by the enterprise. My setup goes as follows to ensure a user's .bashrc is loaded before running any commands via the shell module:Hope this helps as a make-shift solution. It's certainly not ideal, but it gets the job done. I just have to ensure I always prepend {{source_bash}} before any commands run by the shell module.-Steven
Melissa,I have this same situation and ansible's default setup of not using a user's login shell caught me off-guard at first to. It makes sense though for Ansible **not** to want to load the user's environment in order to ensure a consistent shell experience for all modules (especially if a user has zsh as their default for example).The solution I had to use goes against best practices but I'm in the same boat as you where I can't change how sudo is setup on my systems as they are dictated by the enterprise. My setup goes as follows to ensure a user's .bashrc is loaded before running any commands via the shell module:Hope this helps as a make-shift solution. It's certainly not ideal, but it gets the job done. I just have to ensure I always prepend {{source_bash}} before any commands run by the shell module.-Steven
Cmnd_Alias ADMIN_COM = sudoedit /etc/hosts, \/usr/bin/su - ipadm, \/usr/bin/su - ldapadm, \/usr/bin/su - cqadm%apadm ALL=(ALL) NOPASSWD: ADMIN_COM
$ ansible -v -i hosts xqa1app3 -m shell -a 'which tar' -u ipadmxqa1app3 | success | rc=0 >>/usr/bin/tar
$ ansible -v -i hosts xqa1app3 -m shell -a 'echo $PATH' -u ipadmxqa1app3 | success | rc=0 >>/usr/bin:/bin
$ ansible -v -i hosts xqa1app3 -m shell -a 'cat .bashrc' -u ipadmxqa1app3 | success | rc=0 >># .bashrc# Source global definitionsif [ -f /etc/bashrc ]; then. /etc/bashrcfi# User specific aliases and functionsalias cdscr='cd /app/scripts/$USER'alias l.='ls -altr'alias ll='ls -l'if [[ -z $LOGNAME ]]thenalias cdscr='cd /app/scripts/$LOGNAME'fi$ ansible -v -i hosts xqa1app3 -m shell -a 'cat .bash_profile' -u ipadmxqa1app3 | success | rc=0 >># .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then. ~/.bashrcfi# User specific environment and startup programsexport LD_LIBRARY_PATH=/usr/lib64export JAVA_HOME=/usr/jdk/jdk1.6.0_45export LDAP_HOME=/app/servers/ds/dsee7export PATH=$JAVA_HOME/bin:$LDAP_HOME/bin:$HOME/bin:/app/local/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATHexport EDITOR=vi ;
$ ansible -v -i hosts xqa1app3 -m shell -a 'echo $PATH' -u ipadmxqa1app3 | success | rc=0 >>/usr/bin:/bin
$ ansible -v -i hosts xqa1app3 -m shell -a 'echo $PATH' -u ipadmxqa1app3 | success | rc=0 >>/usr/jdk/jdk1.6.0_45/bin:/app/servers/ds/dsee7/bin:/export/home/ipadm/bin:/app/local/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:/usr/bin:/bin
$ ansible -v -i hosts xqa1app3 -m shell -a 'cat .bashrc' -u ipadmxqa1app3 | success | rc=0 >># .bashrc# Source global definitionsif [ -f /etc/bashrc ]; then. /etc/bashrcfi# User specific aliases and functionsalias cdscr='cd /app/scripts/$USER'alias l.='ls -altr'alias ll='ls -l'if [[ -z $LOGNAME ]]thenalias cdscr='cd /app/scripts/$LOGNAME'fi# User specific environment and startup programsexport LD_LIBRARY_PATH=/usr/lib64:$LD_LIBRARY_PATHexport JAVA_HOME=/usr/jdk/jdk1.6.0_45export LDAP_HOME=/app/servers/ds/dsee7export PATH=$JAVA_HOME/bin:$LDAP_HOME/bin:$HOME/bin:/app/local/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATH$ ansible -v -i hosts xqa1app3 -m shell -a 'cat .bash_profile' -u ipadmxqa1app3 | success | rc=0 >># .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then. ~/.bashrcfi# User specific environment and startup programs#export LD_LIBRARY_PATH=/usr/lib64#export JAVA_HOME=/usr/jdk/jdk1.6.0_45#export LDAP_HOME=/app/servers/ds/dsee7#export PATH=$JAVA_HOME/bin:$LDAP_HOME/bin:$HOME/bin:/app/local/bin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin:$PATHexport EDITOR=vi ;
$ ansible -v -i hosts xqa1app3 -m shell -a 'which tar' -u ipadmxqa1app3 | success | rc=0 >>/usr/local/bin/tar
After it is set, I'm faced with a password prompt when no password required is already done. So it is actually executing sudo, but sudo isn't setup to authorized the command that Ansible is pushing through. The sudoers file is not very large and the Unix Sys Admins want to keep it simple... so it pretty much boils down to the following:Cmnd_Alias ADMIN_COM = sudoedit /etc/hosts, \/usr/bin/su - ipadm, \/usr/bin/su - ldapadm, \/usr/bin/su - cqadm%apadm ALL=(ALL) NOPASSWD: ADMIN_COM
thanks a lot!
# Spin-up the VM and bootstrap the server to add python-simplejson & needed packages$ vagrant up --no-provision && ansible-playbook provisioning/init.yml -i provisioning/hosts/vagrant -u vagrant -s--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/rKHzovQYSLY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/aaf25e0e-0210-4ab7-bb45-16835e26f824%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
ansible_python_interpreter: /usr/bin/env python