Idiot check on how register: is supposed to work?

Hello all,

I’m very new to ansible, and hope that this is something very simple that has escaped me.

Here’s what I’m trying to accomplish: I’m doing a task on prior runs that shouldn’t be repeated, so I’m dropping a flag on the system to pick up on future playbook runs.

  • name: Check for prior execution win_stat: path: c:\temp\dc.success register: file_flag - name: Debug Check debug: var: file_flag

TASK [Check for prior execution] ***************************************************************************
task path: /home/ctfadmin/MOONLIGHTWALK/ansible/playbooks/dc1_corp.stage0.yml:61
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/windows/win_stat.ps1
<172.16.1.50> ESTABLISH WINRM CONNECTION FOR USER: ansible on PORT 5985 TO 172.16.1.50
EXEC (via pipeline wrapper)
ok: [172.16.1.50] => {
“changed”: false,
“stat”: {
“attributes”: “Archive”,
“checksum”: “da39a3ee5e6b4b0d3255bfef95601890afd80709”,
“creationtime”: 1498507211.5576174,
“exists”: true,
“extension”: “.success”,
“filename”: “dc.success”,
“isarchive”: true,
“isdir”: false,
“ishidden”: false,
“islnk”: false,
“isreadonly”: false,
“isshared”: false,
“lastaccesstime”: 1498507211.5576174,
“lastwritetime”: 1498508973.9960954,
“md5”: “d41d8cd98f00b204e9800998ecf8427e”,
“owner”: “BUILTIN\Administrators”,
“path”: “C:\temp\dc.success”,
“size”: 0
}
}

TASK [Debug Check] ***************************************************************************************************
task path: /home/ctfadmin/MOONLIGHTWALK/ansible/playbooks/dc1_corp.stage0.yml:65
ok: [172.16.1.50] => {
“file_flag”: “VARIABLE IS NOT DEFINED!”
}

I’m hoping that someone can point out a simple an obvious thing that I’m missing!

Thank you in advance!

-Bobby

Take a look at the stat module. It has slightly better examples of what you are trying to do: http://docs.ansible.com/ansible/stat_module.html

I think your indention is wrong.

You have

  • name: Check for prior execution win_stat: path: c:\temp\dc.success register: file_flag

It should be:

  • name: Check for prior execution win_stat: path: c:\temp\dc.success register: file_flag

I double-checked my test case, and I can can confirm that the indentation is as you suggest, where the register: is aligned with the win_stat. Copying and pasting didn’t work out so well in the post :-/

Hi,

file_flag is not a variable but a json structure

see the doc for stat:

http://docs.ansible.com/ansible/win_stat_module.html

you should instead use

var: file_flag.stat.checksum

M B