I am working on automating a task that should add the latest software to a file. I do not want him to do this several times for the same version.
He looks at the following example file:
var software releases = new Array( "4.3.0", "4.4.0", "4.5.0", "4.7.0", "4.8.0", "4.11.0", "4.12.1", "4.14.0", "4.15.0", "4.16.0", );
by default main.yml will pass something like
VERSION: 4.16.2
the code
- name: register version check shell: cat /root/versions.js | grep -q {{VERSION}} register: current_version - debug: msg="The registered variable output is {{ current_version.rc }}" - name: append to versions.js lineinfile: dest: /root/versions.js regexp: '^\);' insertbefore: '^#\);' line: " \"{{VERSION}}\",\n);" owner: root state: present when: current_version.rc == 1
: The debugging message evaluates current_version.rc and shows me booleans based on the output of the grep commands, but I cannot reuse this in the when to determine whether the task should be executed.
Edit: output:
PLAY [localhost] ************************************************************** GATHERING FACTS *************************************************************** ok: [localhost] TASK: [test | register version check] ***************************************** failed: [localhost] => {"changed": true, "cmd": "cat /root/versions.js | grep -q 3.19.2", "delta": "0:00:00.003570", "end": "2015-12-17 00:24:49.729078", "rc": 1, "start": "2015-12-17 00:24:49.725508", "warnings": []} FATAL: all hosts have already failed -- aborting PLAY RECAP ******************************************************************** to retry, use: --limit @/root/site.retry localhost : ok=1 changed=0 unreachable=0 failed=1
ansible
Bryan
source share