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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/55382b07-3acf-c93d-fa4e-140b164889ee%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to