我有一个shell脚本,当我手动运行它时它工作正常。这是我脚本的结构。
---do some configuration
unbuffer ansible-playbook $path/ansible/deployWebServers.yml -v -i $path/ansible/ansibleInventory.txt > webservers.out &
unbuffer ansible-playbook $path/ansible/deploydbServers.yml -v -i $path/ansible/ansibleInventory.txt > dbservers.out &
tail -q -f dbservers.out -f webservers.out --pid $!
---end
当我从java中调用它时出现此错误
TASK: [wait for SSH to respond on all hosts] **********************************
<127.0.0.1> REMOTE_MODULE wait_for port=22 host=172.24.4.8 delay=10
<127.0.0.1> REMOTE_MODULE wait_for port=22 host=172.24.4.7 delay=10
<127.0.0.1> EXEC ['/bin/bash', '-c', 'mkdir -p /tmp/ansible/pooya/ansible-tmp-1438136055.57-31204886692493 && chmod a+rx /tmp/ansible/pooya/ansible-tmp-1438136055.57-31204886692493 && echo /tmp/ansible/pooya/ansible-tmp-1438136055.57-31204886692493']
<127.0.0.1> EXEC ['/bin/bash', '-c', 'mkdir -p /tmp/ansible/pooya/ansible-tmp-1438136055.57-144898033527375 && chmod a+rx /tmp/ansible/pooya/ansible-tmp-1438136055.57-144898033527375 && echo /tmp/ansible/pooya/ansible-tmp-1438136055.57-144898033527375']
<127.0.0.1> PUT /tmp/tmpPjUpxU TO /tmp/ansible/pooya/ansible-tmp-1438136055.57-31204886692493/wait_for
<127.0.0.1> EXEC ['/bin/bash', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /tmp/ansible/pooya/ansible-tmp-1438136055.57-31204886692493/wait_for; rm -rf /tmp/ansible/pooya/ansible-tmp-1438136055.57-31204886692493/ >/dev/null 2>&1']
<127.0.0.1> PUT /tmp/tmpPmBd4o TO /tmp/ansible/pooya/ansible-tmp-1438136055.57-144898033527375/wait_for
<127.0.0.1> EXEC ['/bin/bash', '-c', u'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /tmp/ansible/pooya/ansible-tmp-1438136055.57-144898033527375/wait_for; rm -rf /tmp/ansible/pooya/ansible-tmp-1438136055.57-144898033527375/ >/dev/null 2>&1']
failed: [172.24.4.8 -> 127.0.0.1] => {"failed": true, "parsed": false}
/bin/bash: /tmp/ansible/pooya/ansible-tmp-1438136055.57-31204886692493/wait_for: Permission denied
我从java中调用我的脚本:
p = Runtime.getRuntime().exec(pathToFile+"/deploy.sh",envArr);
这是我的ansible.cfg
# config file for ansible -- http://ansible.com/
# ==============================================
# nearly all parameters can be overridden in ansible-playbook
# or with command line flags. ansible will read ANSIBLE_CONFIG,
# ansible.cfg in the current working directory, .ansible.cfg in
# the home directory or /etc/ansible/ansible.cfg, whichever it
# finds first
[defaults]
# some basic default values...
hostfile = /etc/ansible/hosts
library = /usr/share/ansible
remote_tmp = /tmp/ansible/pooya
pattern = *
forks = 5
poll_interval = 15
sudo_user = root
#ask_sudo_pass = True
#ask_pass = True
transport = smart
remote_port = 22
# additional paths to search for roles in, colon seperated
#roles_path = /etc/ansible/roles
# uncomment this to disable SSH key host checking
host_key_checking = False
# change this for alternative sudo implementations
sudo_exe = sudo
# what flags to pass to sudo
#sudo_flags = -H
# SSH timeout
timeout = 10
# default user to use for playbooks if user is not specified
# (/usr/bin/ansible will use current user as default)
#remote_user = root
# logging is off by default unless this path is defined
# if so defined, consider logrotate
#log_path = /var/log/ansible.log
# default module name for /usr/bin/ansible
#module_name = command
# use this shell for commands executed under sudo
# you may need to change this to bin/bash in rare instances
# if sudo is constrained
executable = /bin/bash
# if inventory variables overlap, does the higher precedence one win
# or are hash values merged together? The default is 'replace' but
# this can also be set to 'merge'.
#hash_behaviour = replace
# How to handle variable replacement - as of 1.2, Jinja2 variable syntax is
# preferred, but we still support the old $variable replacement too.
# Turn off ${old_style} variables here if you like.
#legacy_playbook_variables = yes
# list any Jinja2 extensions to enable here:
#jinja2_extensions = jinja2.ext.do,jinja2.ext.i18n
# if set, always use this private key file for authentication, same as
# if passing --private-key to ansible or ansible-playbook
#private_key_file = /path/to/file
# format of string {{ ansible_managed }} available within Jinja2
# templates indicates to users editing templates files will be replaced.
# replacing {file}, {host} and {uid} and strftime codes with proper values.
ansible_managed = Ansible managed: {file} modified on %Y-%m-%d %H:%M:%S by {uid} on {host}
# by default, ansible-playbook will display "Skipping [host]" if it determines a task
# should not be run on a host. Set this to "False" if you don't want to see these "Skipping"
# messages. NOTE: the task header will still be shown regardless of whether or not the
# task is skipped.
#display_skipped_hosts = True
# by default (as of 1.3), Ansible will raise errors when attempting to dereference
# Jinja2 variables that are not set in templates or action lines. Uncomment this line
# to revert the behavior to pre-1.3.
#error_on_undefined_vars = False
# set plugin path directories here, seperate with colons
action_plugins = /usr/share/ansible_plugins/action_plugins
callback_plugins = /usr/share/ansible_plugins/callback_plugins
connection_plugins = /usr/share/ansible_plugins/connection_plugins
lookup_plugins = /usr/share/ansible_plugins/lookup_plugins
vars_plugins = /usr/share/ansible_plugins/vars_plugins
filter_plugins = /usr/share/ansible_plugins/filter_plugins
# don't like cows? that's unfortunate.
# set to 1 if you don't want cowsay support or export ANSIBLE_NOCOWS=1
#nocows = 1
# don't like colors either?
# set to 1 if you don't want colors, or export ANSIBLE_NOCOLOR=1
#nocolor = 1
# the CA certificate path used for validating SSL certs. This path
# should exist on the controlling node, not the target nodes
# common locations:
# RHEL/CentOS: /etc/pki/tls/certs/ca-bundle.crt
# Fedora : /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
# Ubuntu : /usr/share/ca-certificates/cacert.org/cacert.org.crt
#ca_file_path =
# the http user-agent string to use when fetching urls. Some web server
# operators block the default urllib user agent as it is frequently used
# by malicious attacks/scripts, so we set it to something unique to
# avoid issues.
#http_user_agent = ansible-agent
[paramiko_connection]
# uncomment this line to cause the paramiko connection plugin to not record new host
# keys encountered. Increases performance on new host additions. Setting works independently of the
# host key checking setting above.
#record_host_keys=False
# by default, Ansible requests a pseudo-terminal for commands executed under sudo. Uncomment this
# line to disable this behaviour.
#pty=False
[ssh_connection]
# ssh arguments to use
# Leaving off ControlPersist will result in poor performance, so use
# paramiko on older platforms rather than removing it
#ssh_args = -o ControlMaster=auto -o ControlPersist=60s
# The path to use for the ControlPath sockets. This defaults to
# "%(directory)s/ansible-ssh-%%h-%%p-%%r", however on some systems with
# very long hostnames or very long path names (caused by long user names or
# deeply nested home directories) this can exceed the character limit on
# file socket names (108 characters for most platforms). In that case, you
# may wish to shorten the string below.
#
# Example:
# control_path = %(directory)s/%%h-%%r
#control_path = %(directory)s/ansible-ssh-%%h-%%p-%%r
# Enabling pipelining reduces the number of SSH operations required to
# execute a module on the remote server. This can result in a significant
# performance improvement when enabled, however when using "sudo:" you must
# first disable 'requiretty' in /etc/sudoers
#
# By default, this option is disabled to preserve compatibility with
# sudoers configurations that have requiretty (the default on many distros).
#
#pipelining = False
# if True, make ansible use scp if the connection type is ssh
# (default is sftp)
#scp_if_ssh = True
[accelerate]
accelerate_port = 5099
accelerate_timeout = 30
accelerate_connect_timeout = 5.0
我在另一个系统中遇到了这个问题我通过将remote_tmp变量更改为/tmp/ansible/${USER}
解决了这个问题,但是在这个系统中它似乎无法识别$ USER所以我手动设置了我的用户,但我仍然遇到此错误。
这是ll / | grep tmp
的输出:
drwxrwxrwt 10 root root 4096 Jul 28 19:21 tmp/