Thanks for the response/idea Kai. I was too focused on making it work the 
other way to consider breaking it up like that.

I ran with the idea of grabbing the last log line in a separate task and 
using a when conditional however now i'm running into a different issue. 
Since i'm now using variables for the conditional it's complaining about 
"template error while templating string: unexpected char u'a' at 8.. Not 
sure what this error means exactly. 

Here's the full tasks/output:

http://pastebin.com/TsdB5ZFe

a little googling led me to this 
post 
https://groups.google.com/forum/#!msg/ansible-project/mLgdORSFspo/PXfO76QNfMMJ 
but i'm not sure where I would apply the raw syntax in there or if it even 
applies.

On Wednesday, July 27, 2016 at 10:26:24 AM UTC-4, Kai Stian Olstad wrote:
>
> On 26. juli 2016 23:09, Jason Gilfoil wrote: 
> > I apologize if this isn't an strictly an ansible problem, but I'm 
> > attempting to run a command like the following which works when run 
> > directly on the server in bash but fails when I try running via ansible. 
> > 
> >   - name: write commit to history 
> >     shell: "[[ $(tail -1 
> > /app/psoft/install_logs/deployment_version_history.log) != 
> > '81cdc80ec7fdb0201e00fe2f8767b10ec136c687 peoplesoft.yml' ]] && { echo 
> > '81cdc80ec7fdb0201e00fe2f8767b10ec136c687 peoplesoft.yml' >> 
> > /app/psoft/install_logs/deployment_version_history.log; }" 
> > 
> > 
> > output: 
> > 
> > fatal: [net12204]: FAILED! => {"changed": true, "cmd": "[[ $(tail -1 
> > /app/psoft/install_logs/deployment_version_history.log) != 
> > '81cdc80ec7fdb0201e00fe2f8767b10ec136c687 peoplesoft.yml' ]] && { echo 
> > '81cdc80ec7fdb0201e00fe2f8767b10ec136c687 peoplesoft.yml' >> 
> > /app/psoft/install_logs/deployment_version_history.log; }", "delta": 
> > "0:00:00.006239", "end": "2016-07-26 16:58:47.826353", "failed": true, 
> > "rc": 1, "start": "2016-07-26 16:58:47.820114", "stderr": "", "stdout": 
> "", 
> > "stdout_lines": [], "warnings": []} 
>
> Shell in Ansible is using /bin/sh, depending on your distribution sh 
> usually has limited functionality. So things like [[ ]] and $() might 
> not work. 
>
>
> > The full explanation of what i'm trying to do is create a log with the 
> > history of ansible plays run and their version in git that have been run 
> > against the target application. In the full script the commit hash will 
> be 
> > coming from a register variable in a previous step, but i can't even get 
> a 
> > basic case to run with all the competing special characters. The command 
> is 
> > supposed to look at a log file and compare the last entry to the current 
> > entry to be written and if they're not the same, to add the entry to the 
> > end of the file. I tried doing this more simply with lineinfile but it 
> > would only write if the line didn't exist somewhere else in the 
> file(which 
> > is not what i want). 
> > 
> > Thanks in advance for any advice/help given. 
>
> There is a few ways to solve it, make script or do something like this: 
>
> - name: Get last log 
>    command: tail -1 /app/psoft/install_logs/deployment_version_history.log 
>    register: mylog 
>
> - name: Update log 
>    shell: echo "81cdc80ec7fdb0201e00fe2f8767b10ec136c687 peoplesoft.yml" 
>  >> /app/psoft/install_logs/deployment_version_history.log 
>    when: mylog.stdout != "81cdc80ec7fdb0201e00fe2f8767b10ec136c687 
> peoplesoft.yml" 
>
> -- 
> Kai Stian Olstad 
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/24908f52-714c-4f53-b925-b8719de100f6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to