Ansible does not give the output as same as the script itself - ansible

There is a script that I need to run on a specified server. To do that I use ansible playbooks. Only purpose of the playbook is running the script and getting the output but it is not same when I run the script on its own server.
This is the script I run:
echo ""
cd /kafka/confluent-7.0.1/bin
connectors=$(curl --silent -X GET http://connector-server:8083/connectors)
total=$(echo $connectors|jq '. | length')
counter=0
while [[ $counter < $total ]]
do
single=$(echo $connectors|jq .[$counter] -r)
if [[ $single = sink* ]] ;
then
silent=$(source kafka-consumer-groups --describe --group connect-$single --bootstrap-server kafka-server:9072 --command-config /kafka/vty/cli_sasl.properties)
partitions=$(echo -n "$silent" | grep -c '^')
partitions=$(( partitions - 2 ))
part_counter=0
echo "${single}"
while [[ $part_counter < $partitions ]]
do
lagpos=$(( 15 + $part_counter * 9 ))
lag=$(echo $silent | cut -d " " -f $lagpos)
echo "partition${part_counter}: ${lag} "
((part_counter++))
done
echo ""
fi
((counter++))
done
It gives an simple output like:
sink_connector1
partition0: 0
sink_connector2
partition0: 2
partition1: 3
partition2: 3
sink_connector3
partition0: 0
And here is the playbook I run on ansible server:
- hosts: all
gather_facts: no
connection: ssh
become: yes
become_user: kafka
tasks:
- name: Run Command
shell: cd /kafka/vty && ./lagcheck.sh
register: out
- debug: var=out.stdout_lines
But in the output lag values are empty:
TASK [Run Command] ************************************************************************************************************************************************************
changed: [connector-server]
TASK [debug] ******************************************************************************************************************************************************************
ok: [connector-server] => {
"out.stdout_lines": [
"",
"sink_connector1",
"partition0: ",
"partition1: ",
"partition2: ",
"",
"sink_connector2",
"partition0: ",
"partition1: ",
"partition2: ",
"",
"sink_connector3",
"partition0: ",
"partition1: ",
"partition2: "
]
}
What could be the reason? I was suspicious about no-new-line echos but it does not matter.

Due to all the "bash-isms" in the script, it is likely there is a difference between your interactive user's shell configuration and the non-interactive user that ansible uses. Explicitly using bash to run the script can tell ansible about your preference:
- hosts: all
gather_facts: no
connection: ssh
become: yes
become_user: kafka
tasks:
- name: Run Command
shell: cd /kafka/vty && bash ./lagcheck.sh
register: out

Related

Error in in codebuild while executing if else condition inside for loop

Below is my buildspec.yaml file to list the images inside ecr and I'm using to for loop and if elese condition to find a particular imageId exists or not
version: 0.2
phases:
install:
runtime-versions:
nodejs: 12
commands:
- echo test
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws --version
- $(aws ecr get-login --region $AWS_DEFAULT_REGION --no-include-email)
build:
commands:
- aws ecr list-images --repository-name mytestecrrepo > ecr.json
- cat ecr.json
- for imageTag in $(jq -r '.imageIds[].imageTag' < ecr.json); do
if [ $imageTag = "1.0" ]; then
echo "value exists"
else
echo "value doesntexists"
fi
done
post_build:
commands:
- echo Build completed on `date`
For some reason, code build is throwing the below error
/codebuild/output/tmp/script.sh: line 9: syntax error: unexpected end of file
I'm doing something wrong within the shell script?
You can try the following in your build:
build:
commands:
- aws ecr list-images --repository-name mytestecrrepo > ecr.json
- cat ecr.json
- |
for imageTag in $(jq -r '.imageIds[].imageTag' < ecr.json); do
if [ $imageTag = "1.0" ]; then
echo "value exists"
else
echo "value doesntexists"
fi
done

How to set ansible playbook to run with kornshell

Writing ansible-playbook, to start a kornshell script.
How to set ansible to run kornshell in specific server?
---
- name: Start server manager agent
hosts: 192.168.1.85
become: yes
become_user: jde920
tasks:
- name: Set ksh
shell: ksh (not sure how to set here)
- name: start Agent
async: 10
poll: 0
shell: "./startAgent"
args:
chdir: "/u01/jde_home/SCFHA/bin/"
- name: Wait for 5 seconds
wait_for:
timeout: 5
- name: Start Service
async: 10
poll: 0
#ansible_shell_executable: ksh
shell: "./RunOneWorld.sh"
args:
chdir: "/u01/jdedwards/e920/system/bin32/"
- name: Validate Service is up
tags: JDE_Enterprise
wait_for:
host: "localhost"
port: 6017
delay: 20
timeout: 60
state: started
msg: "JDE Enterprise Service is not Running"
I managed to find the file that set the environment $SYSTEM, following is the code. Script file name is call enterpriseone.sh
# Following has to be replaced in this file:
#
# ORACLE_HOME (if Oracle is installed)
# DB2DIR (if DB2 is installed)
# DB2INSTANCE name of user owning DB2 instance
# File Updated Tue Mar 05 16:37:23 MYT 2019 - TR 9.2.3
OS_NAME=`uname -s`
EVRHOME=/u01/jdedwards/e920
export EVRHOME
DB2INSTANCE=
export DB2INSTANCE
DB2DIR=
export DB2DIR
DB2BASEDIR=
export DB2BASEDIR
ORCL_USER_ACCT=
export ORCL_USER_ACCT
ORACLE_HOME=/u01/oracle/product/12.1.0/client_1
export ORACLE_HOME
ORACLE_SID=e1db
export ORACLE_SID
set +u
SYSTEM=$EVRHOME/system
export SYSTEM
APPDEV=$EVRHOME/appdev
export APPDEV
#
# Location of INI files
JDE_BASE=$EVRHOME/ini
export JDE_BASE
## Set the binary folder to 32 or 64 bit based on the setup configuration
if [ $OS_NAME = "HP-UX" ]; then
BUILDTYPE=$(file $SYSTEM/lib/libjdenet.so | grep 'ELF-64')
else
BUILDTYPE=$(file $SYSTEM/lib/libjdenet.so | grep '64-bit')
fi
if [ -n "$BUILDTYPE" ]; then
BIN_FOLDER=bin64
else
BIN_FOLDER=bin32
fi
PATH=$PATH:$SYSTEM/$BIN_FOLDER
export PATH
ICU_DATA=$SYSTEM/locale/xml/
export ICU_DATA
ACRO_RES_DIR=$SYSTEM/resource/cmap
export ACRO_RES_DIR
PSRESOURCEPATH=$SYSTEM/resource/cidfont:$ACRO_RES_DIR
export PSRESOURCEPATH
#
# Call tools service pack specific environment variable
# setup script. This script is required for running
# the enterprise server. If this script does not exist
# in your $SYSTEM/$BIN_FOLDER directory, the E1 Tools Release
# may need to be updated to a newer version.
if [ -f ${SYSTEM}/$BIN_FOLDER/toolsenv.sh ] ; then
. ${SYSTEM}/$BIN_FOLDER/toolsenv.sh
fi
Below is the actual shell script (RunOneWorld.sh) that I use ansible to call:
## Set the binary folder to 32 or 64 bit based on the setup configuration
OS_NAME=`uname -s`
if [ $OS_NAME = "HP-UX" ]; then
BUILDTYPE=$(file $SYSTEM/lib/libjdenet.so | grep 'ELF-64')
else
BUILDTYPE=$(file $SYSTEM/lib/libjdenet.so | grep '64-bit')
fi
if [ -n "$BUILDTYPE" ]; then
BIN_FOLDER=bin64
else
BIN_FOLDER=bin32
fi
LOGFILE=$SYSTEM/$BIN_FOLDER"/startstop.log"
## Set START_NEW_LOGFILE=1 if you want to rewrite the logfile at each startup
START_NEW_LOGFILE=0
CLEAR_LOGS=1
## Set MULTI_INSTANCE=1 if you are running multiple instances of OneWorld
## under the same Unix user id.
MULTI_INSTANCE=0
set +u
USER=$(whoami)
HOST=$(hostname)
OSTYPE=$(uname)
## On AIX, process id shows up in column 2, it's column 1 on others...
if [ $OSTYPE = "AIX" ]
then
COLUMN=2
else
COLUMN=1
fi
unset SILENT_MODE
if [ "$1" = "-s" ] ; then
SILENT_MODE=1
fi
## In MULTI_INSTANCE mode, we need to be able to find the INI file to get
## certain settings. If we can't, then exit with an error.
if [ "$MULTI_INSTANCE" = "1" ] ; then
MFLAG="-m"
if [ -f ./JDE.INI ] ; then
PORT_NBR=$(grep "^serviceNameListen" ./JDE.INI | sed 's/.*=//')
elif [ -f $JDE_BASE/JDE.INI ] ; then
PORT_NBR=$(grep "^serviceNameListen" $JDE_BASE/JDE.INI | sed 's/.*=//')
else
if [ -z "$SILENT_MODE" ] ; then
print " This script cannot support multiple instances of"
print " OneWorld without access to a JDE.INI file."
print " You must either set the $JDE_BASE environment"
print " variable correctly, or turn off MULTI_INSTANCE"
print " mode in the RunOneWorld.sh script."
print " exiting..."
fi
print " This script cannot support multiple instances of" >> $LOGFILE
print " OneWorld without access to a JDE.INI file." >> $LOGFILE
print " You must either set the $JDE_BASE environment" >> $LOGFILE
print " variable correctly, or turn off MULTI_INSTANCE" >> $LOGFILE
print " mode in the RunOneWorld.sh script." >> $LOGFILE
print " exiting..." >> $LOGFILE
exit 1
fi
fi
#---------------------------------------------------------------------- #
# FUNCTION DEFINITIONS...
#---------------------------------------------------------------------- #
function GetPIDS
{
if [ "$MULTI_INSTANCE" = "1" ]
then
PIDS=$(ps -ef | grep $USER | grep $PORT_NBR | grep -v grep | awk '{print $2}')
PIDS="$(ps -ef | grep $USER | grep $SYSTEM | grep -v grep | awk '{print $2}') $PIDS"
else
PIDS=$(ps -u $USER | grep jdenet | awk '{print $'$COLUMN'}')
fi
if [ "$PIDS" = " " ] ; then
PIDS=""
fi
}
function CheckForProcesses
{
GetPIDS
if [ -n "$PIDS" ] ; then
if [ -z "$SILENT_MODE" ] ; then
print " There are already OneWorld processes"
print " running for this user / instance..."
print " exiting..."
fi
print " There are already OneWorld processes" >> $LOGFILE
print " running for this user / instance..." >> $LOGFILE
print " exiting..." >> $LOGFILE
exit 1
fi
}
function CheckIPC
{
$SYSTEM/$BIN_FOLDER/rmics.sh $MFLAG >> $LOGFILE
if [ ! $? = 0 ] ; then
if [ -z "$SILENT_MODE" ] ; then
print " IPC resource conflict -"
print " You may need to change the startIPCKeyValue in your INI file,"
print " or your JDE_BASE environment variable may be set incorrectly."
print " exiting..."
fi
## (error message already written to $LOGFILE by rmics.sh)
exit 1
fi
}
#---------------------------------------------------------------------- #
# MAIN PROCESSING...
#---------------------------------------------------------------------- #
## First, let's make sure the log file directory is valid - otherwise, all
## of the log messages will disappear.
LOGDIR=$(dirname $LOGFILE)
if [ ! -d $LOGDIR ] ; then
print " Invalid directory name for LOGFILE - "
print " $LOGDIR"
print " You must correct RunOneWorld.sh and retry."
exit 1
fi
if [ "$START_NEW_LOGFILE" = "1" ] ; then
rm $LOGFILE
fi
if [ "$CLEAR_LOGS" = "1" ] ; then
## If the log directory is a link, figure out what it points to...
if [ -L $EVRHOME/log ]; then
REAL_LOGDIR=$(ls -l $EVRHOME/log | awk '{print $NF}')
else
REAL_LOGDIR=$EVRHOME/log
fi
rm -rf $REAL_LOGDIR.prev
mv $REAL_LOGDIR $REAL_LOGDIR.prev
mkdir $REAL_LOGDIR
fi
print "**********************************************************" >> $LOGFILE
if [ ! $? = 0 ] ; then
print " Unable to write to the logfile - "
print " $LOGFILE"
print " You might not have permission to write to this file or directory."
print " Make sure file permissions are set correctly and retry."
exit 1
fi
if [ -z "$SILENT_MODE" ] ; then
print "$(date) Starting JD Edwards OneWorld on $HOST"
fi
print "$(date) Starting JD Edwards OneWorld on $HOST" >> $LOGFILE
CheckForProcesses
if [ ! "$1" = "-n" ] ; then
CheckIPC
fi
print " Starting jdenet_n..." >> $LOGFILE
cd $SYSTEM/$BIN_FOLDER
$SYSTEM/$BIN_FOLDER/jdenet_n > $SYSTEM/$BIN_FOLDER/jdenet_n.log 2>&1 &
sleep 2
GetPIDS
if [ -z "$PIDS" ] ; then
if [ -z "$SILENT_MODE" ] ; then
print " The jdenet_n process did not start..."
print " Check the jdenet_n.log, or the log file associated"
print " with the jdenet_n process id."
fi
print " The jdenet_n process did not start..." >> $LOGFILE
print " Check the jdenet_n.log, or the log file associated" >> $LOGFILE
print " with the jdenet_n process id." >> $LOGFILE
exit 1
fi
print " Running cleanup to check for unfinished jobs..." >> $LOGFILE
$SYSTEM/$BIN_FOLDER/cleanup &
if [ -z "$SILENT_MODE" ] ; then
print "\n$(date) JD Edwards OneWorld startup complete.\n"
fi
print "\n$(date) JD Edwards OneWorld startup complete.\n" >> $LOGFILE
exit 0
SO in order to start the service, I will just do command as follow:
cd $SYSTEM/bin32
./RunOneWorld.sh
For shell module, use the executable parameter instead
- name: Start Service
async: 10
poll: 0
shell: "./RunOneWorld.sh"
args:
chdir: "/u01/jdedwards/e920/system/bin32/"
executable: /bin/ksh
I have changed accordingly to the following, but the script still doesn't run.
---
- name: Start server manager agent
hosts: 192.168.1.85
become: yes
become_user: jde920
tasks:
- name: start Agent
async: 10
poll: 0
shell: "./startAgent"
args:
chdir: "/u01/jde_home/SCFHA/bin/"
- name: Wait for 5 seconds
wait_for:
timeout: 5
- name: Start JDE Enterprise Service
async: 10
poll: 0
shell: "./RunOneWorld.sh"
args:
chdir: "/$SYSTEM/bin32/"
executable: /usr/bin/ksh
- name: Validate JDE Enterprise Service is up
tags: JDE_Enterprise
wait_for:
host: "localhost"
port: 6017
delay: 20
timeout: 60
state: started
msg: "JDE Enterprise Service is not Running"
I tried to manually verified and it runs in the actual server.
$ /usr/bin/ksh /$SYSTEM/bin32/RunOneWorld.sh
Wed Apr 15 14:17:03 +08 2020 Starting JD Edwards OneWorld on CBD2ELENT
Wed Apr 15 14:17:05 +08 2020 JD Edwards OneWorld startup complete.

Ansible shell module fails and errors on AiX system

Below is my playbook having a shell module:
Note: mypid variable is the process id of a process running on target host.
- shell: |
if [ -z {{tm}} ]; then mypid="wrongpid"; else mypid= {{tm}}; fi;
if [ ! -e /proc/$mypid/status ]; then exit 1; fi
istat {{fn}} | grep -i Modif | cut -d' ' -f3,4,5,6
vars:
fn: "/proc/{{ mypid }}/status"
tm: "{{ mypid }}"
tags: always
ignore_errors: yes
register: starttime
This worked fine on Linux systems. On AiX though this shell module fails with the below error:
TASK [shell] *******************************************************************
[1;30mtask path: /app/playbook/startstop.yml:318[0m
[0;31mfatal: [10.9.9.131]: FAILED! => {"changed": true, "cmd": "if [ -z 12386652 ]; then mypid=\"wrongpid\"; else mypid= 12386652; fi;\nif [ ! -e /proc/$mypid/status ]; then exit 1; fi\nistat /proc/12386652/status | grep -i Modif | cut -d' ' -f3,4,5,6\n", "delta": "0:00:00.108227", "end": "2019-11-21 14:09:35.064768", "msg": "non-zero return code", "rc": 1, "start": "2019-11-21 14:09:34.956541", "stderr": "/bin/sh: 12386652: not found.", "stderr_lines": ["/bin/sh: 12386652: not found."], "stdout": "", "stdout_lines": []}[0m
[0;36m...ignoring[0m
I added the below shell args but still the error remains:
args:
executable: /bin/ksh
Running the shell on the target server as a shell script also works fine. Don't know why is is failing in the ansible playbook.
Kindly suggest.
You have an extra space in your shell var assignment expression causing sh to try to execute a command rather that assigning the var:
else mypid= {{tm}} => else mypid={{tm}}
Moreover, you should secure the entire expression a bit to make sure you don't get other surprises (with empty params for example...)
# before
if [ -z {{tm}} ]; then mypid="wrongpid"; else mypid= {{tm}}; fi;
# after
if [ -z "{{tm}}" ]; then mypid="wrongpid"; else mypid="{{tm}}"; fi;

Ansible concatenate 2 files with jinja2 template

I am trying to vertically concatenate 2 files
The 1st file is roles/myrolename/files/requirements.dat
numpy
matplotlib
dask
and the 2nd file is ~/myprojects/myprojectname/requirements.txt
django
pywinrm
scipy
Here is my attempt to combine these 2 files, based on
this SO post
the include jinja2 documentation
Here is the task I am using
- name: Play to combine 2 files
hosts: localhost
connection: local
vars:
myprojects_path: myprojects
my_proj_name: myprojectname
tasks:
- name: Concatenate 2 files
template:
src: "roles/myrolename/templates/requirements.dat.j2"
dest: "{{ myprojects_path }}/{{ my_proj_name }}/requirements.dat"
Here is roles/myrolename/templates/requirements.dat.j2
{% include 'roles/myrolename/files/requirements.dat' %}
{% include myprojects_path + "/" + my_proj_name + "/" + "requirements.txt" %}
This task gives the error message (related to the 2nd include statement from roles/myrolename/templates/requirements.dat.j2)
fatal: [my_local_machine]: FAILED! => {"changed": false,
"msg": "TemplateNotFound: /home/wr/myprojects/myprojectname/requirements.txt"}
This seems to suggest that Ansible is expecting that /home/wr/myprojects/myprojectname/requirements.txt is a template and not a file. However, the first include line does not throw an error. This is confusing me.
Is there a way I can use include to concatenate these 2 files with the jinja2 template, or is there another method to concatenate the 2 files?
EDIT 1:
I added {# a comment #} to the 1st line of requirements.txt. Here is the new ~/myprojects/myprojectname/requirements.txt
{# a comment #}
django
pywinrm
scipy
Then, I re-ran the playbook ansible-playbook test.yml -vvv. Here is the output
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: wr
<127.0.0.1> EXEC /bin/sh -c 'echo ~wr && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/wr/.ansible/tmp/ansible-tmp-1532962816.77-184726406959930 `" && echo ansible-tmp-1532962816.77-184726406959930="` echo /home/wr/.ansible/tmp/ansible-tmp-1532962816.77-184726406959930 `" ) && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/wr/.ansible/tmp/ansible-tmp-1532962816.77-184726406959930/ > /dev/null 2>&1 && sleep 0'
fatal: [wr-box]: FAILED! => {
"changed": false,
"msg": "TemplateNotFound: /home/wr/myprojects/myprojectname/requirements.txt"
}
EDIT 2:
I tried to ask Ansible to treat the above requirements.txt (with {# a comment #} on 1st line) as a jinja2 template by re-naming the file. I renamed the file requirements.txt to requirements.txt.j2 and re-ran the playbook. It gives this output
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: wr
<127.0.0.1> EXEC /bin/sh -c 'echo ~wr && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/wr/.ansible/tmp/ansible-tmp-1532963056.03-76693523230507 `" && echo ansible-tmp-1532963056.03-76693523230507="` echo /home/wr/.ansible/tmp/ansible-tmp-1532963056.03-76693523230507 `" ) && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/wr/.ansible/tmp/ansible-tmp-1532963056.03-76693523230507/ > /dev/null 2>&1 && sleep 0'
fatal: [wr-box]: FAILED! => {
"changed": false,
"msg": "TemplateNotFound: /home/wr/myprojects/myprojectname/requirements.txt.j2"
}
It still does not seem to find the template file, even though I have checked that it is indeed present at the location I specified.
Generally the include statement treats the file as a template. Also the file requirements.txt in your example is generally a template, without variables and with text only.
Does the file /home/wr/myprojects/myprojectname/requirements.txt exist?

Ansible can't resolve host name error

Currently trying to run just a simple playbook on an Ansible install on Centos7, everything is up to date. I can run a simple raw module and specify the host but when I run the playbook I have get a "cannot resolve host name"
Here are the logs
[root#ohnetwork01 playbooks]# ansible-playbook -vvvvvv -u user.user -k version_playbook.yaml
Using /etc/ansible/ansible.cfg as config file
SSH password:
Loaded callback default of type stdout, v2.0
PLAYBOOK: version_playbook.yaml ************************************************
1 plays in version_playbook.yaml
PLAY [Get version] *************************************************************
TASK [setup] *******************************************************************
<192.168.1.34> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.34> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529280.8-264756931089857 `" && echo ansible-tmp-1466529280.8-264756931089857="` echo /tmp/ansible/ansible-tmp-1466529280.8-264756931089857 `" ) && sleep 0'
<192.168.1.33> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.33> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529280.8-152708795243660 `" && echo ansible-tmp-1466529280.8-152708795243660="` echo /tmp/ansible/ansible-tmp-1466529280.8-152708795243660 `" ) && sleep 0'
<192.168.1.34> PUT /tmp/tmpymgKXv TO /tmp/ansible/ansible-tmp-1466529280.8-264756931089857/setup
<192.168.1.34> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529280.8-264756931089857/setup; rm -rf "/tmp/ansible/ansible-tmp-1466529280.8-264756931089857/" > /dev/null 2>&1 && sleep 0'
<192.168.1.33> PUT /tmp/tmpW5FEgv TO /tmp/ansible/ansible-tmp-1466529280.8-152708795243660/setup
<192.168.1.33> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529280.8-152708795243660/setup; rm -rf "/tmp/ansible/ansible-tmp-1466529280.8-152708795243660/" > /dev/null 2>&1 && sleep 0'
ok: [P-9396PXb.domain.local]
ok: [P-9396PXa.domain.local]
TASK [nxos_facts] **************************************************************
task path: /home/user/playbooks/version_playbook.yaml:8
<192.168.1.33> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.33> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529281.26-258697976681834 `" && echo ansible-tmp-1466529281.26-258697976681834="` echo /tmp/ansible/ansible-tmp-1466529281.26-258697976681834 `" ) && sleep 0'
<192.168.1.34> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.34> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529281.26-135897636845763 `" && echo ansible-tmp-1466529281.26-135897636845763="` echo /tmp/ansible/ansible-tmp-1466529281.26-135897636845763 `" ) && sleep 0'
<192.168.1.33> PUT /tmp/tmpvaaDMQ TO /tmp/ansible/ansible-tmp-1466529281.26-258697976681834/nxos_facts
<192.168.1.33> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529281.26-258697976681834/nxos_facts; rm -rf "/tmp/ansible/ansible-tmp-1466529281.26-258697976681834/" > /dev/null 2>&1 && sleep 0'
<192.168.1.34> PUT /tmp/tmpK7TYAS TO /tmp/ansible/ansible-tmp-1466529281.26-135897636845763/nxos_facts
<192.168.1.34> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529281.26-135897636845763/nxos_facts; rm -rf "/tmp/ansible/ansible-tmp-1466529281.26-135897636845763/" > /dev/null 2>&1 && sleep 0'
fatal: [P-9396PXa.domain.local]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"host": "", "password": null, "port": null, "provider": null, "ssh_keyfile": null, "transport": "cli", "use_ssl": false, "username": null, "validate_certs": true}, "module_name": "nxos_facts"}, "msg": "failed to connect to :22 - unable to resolve host name"}
fatal: [P-9396PXb.domain.local]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"host": "", "password": null, "port": null, "provider": null, "ssh_keyfile": null, "transport": "cli", "use_ssl": false, "username": null, "validate_certs": true}, "module_name": "nxos_facts"}, "msg": "failed to connect to :22 - unable to resolve host name"}
NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit #version_playbook.retry
PLAY RECAP *********************************************************************
P-9396PXa.domain.local : ok=1 changed=0 unreachable=0 failed=1
P-9396PXb.domain.local : ok=1 changed=0 unreachable=0 failed=1
and here's the host file and playbook I'm using, insanely simple as I was just trying to test
#### Host entry ####
[ProdCoreSwitches]
P-9396PXa.domain.local ansible_host=192.168.1.33
P-9396PXb.domain.local ansible_host=192.168.1.34
#### Playbook ####
---
- name: Get version
connection: local
hosts: ProdCoreSwitches
tasks:
- nxos_facts:
host= "{{ inventory_hostname }}"
Anything I should be changing?
Edit: After changing the connection from local I get the following:
fatal: [P-9396PXa.domain.local]: UNREACHABLE! => {"changed": false, "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" && echo ansible-tmp-1466538148.97-100745005340782=\"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" ), exited with result 16: Syntax error while parsing '/bin/sh -c '( umask 77 && mkdir -p \"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" && echo ansible-tmp-1466538148.97-100745005340782=\"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" ) && sleep 0''\n\n\nCmd exec error.\n", "unreachable": true}
Can you show the content of task "nxos_facts"? Also where did you define "{{ inventory_hostname }}" and what's the value(s)?

Resources