Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save temporary ansible shell scripts instead of deleting

I noticed Ansible removes the temporary script using a semi-colon to separate the bash commands.

Here is an example command:

EXEC ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o  ControlPath="/Users/devuser/.ansible/cp/ansible-ssh-%h-%p-%r" -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 build /bin/sh -c 'LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 /usr/bin/python /home/ec2-user/.ansible/tmp/ansible-tmp-1430847489.81-75617096172775/docker; rm -rf /home/ec2-user/.ansible/tmp/ansible-tmp-1430847489.81-75617096172775/ >/dev/null 2>&1' 

Is there a way to tell ansible to replace the semi-colon with a double ampersand or to tell it to save the script or output the contents when running ansible-playbook?

I'm trying to debug an error in this script and right now the only thing that appears is this:

failed: [build] => {"changed": false, "failed": true} msg: ConnectionError(ProtocolError('Connection aborted.', error(2, 'No such file or directory')),) 
like image 245
Josh Unger Avatar asked May 05 '15 18:05

Josh Unger


People also ask

What is tmp in Ansible?

The tempfile module creates temporary files and directories. mktemp command takes different parameters on various systems, this module helps to avoid troubles related to that. Files/directories created by module are accessible only by creator. In case you need to make them world-accessible you need to use ansible.

What is VVV in Ansible?

Use the -vvv option to make Ansible more verbose. This will display the file name of the temporary module file.

How do I keep secret data on my playbook Ansible?

How do I keep secret data in my playbook? ¶ If you would like to keep secret data in your Ansible content and still share it publicly or keep things in source control, see Vault. This can be used to keep verbose output but hide sensitive information from others who would otherwise like to be able to see the output.

How do I debug Ansible code?

You can enable the task debugger globally with a setting in ansible. cfg or with an environment variable. The only options are True or False . If you set the configuration option or environment variable to True , Ansible runs the debugger on failed tasks by default.


1 Answers

I found the environment variable -

export ANSIBLE_KEEP_REMOTE_FILES=1 

Set this, then re-run ansible-playbook, and then ssh and cd over to ~/.ansible/tmp/ to find the files.

like image 134
Josh Unger Avatar answered Sep 22 '22 20:09

Josh Unger