Hi,
The following are facts from win_pagefile query. From these, I want to
retrieve the "maximum_size" fact of every element in the "pagefiles" array,
then subtract the "initial_size" fact and divide that by 1024 in order to
get every pagefile disk (in GB) to help automate a report on windows
servers.
First, I am attempting to get only the "maximum_size" fact of every element
in the array. Below are attempts at retrieving this fact using the
with_sequence loop...wthout success. Please, help me to review which syntax
would work or if there's any other way. I'd be really grateful.
ok: [10.240.30.249] => {
"win_pf": {
"automatic_managed_pagefiles": false,
"changed": false,
"failed": false,
"pagefiles": [
{
"caption": "c:\\ 'pagefile.sys'",
"description": "'pagefile.sys' @ c:\\",
"initial_size": 0,
"maximum_size": 0,
"name": "c:\\pagefile.sys"
},
{
"caption": "e:\\ 'pagefile.sys'",
"description": "'pagefile.sys' @ e:\\",
"initial_size": 3583,
"maximum_size": 9133,
"name": "e:\\pagefile.sys"
}
]
}
}
Below there are a number of ways I have tried:
---
- hosts: all
vars_files:
- winrms.yml
tasks:
- name: Saving facts into win_pf variable
win_pagefile:
register: win_pf
- name: Set number of disks from where to retrieve facts
set_fact:
listapag: "{{win_pf.pagefiles|length - 1}}"
Here is where I struggle:
Attempt 1:
- name: save m_size
set_fact:
list_ms: "{{win_pf.pagefiles[item].maximum_size}}"
with_sequence:
- start=0 end={{lista}}
Gives error:
TASK [save m_size]
*********************************************************************************************
fatal: [10.240.30.249]: FAILED! => {"msg": "The task includes an option
with an undefined variable. The error was: 'list object' has no attribute
u'0'\n\nThe error appears to be in
'/home/gabriel/Conex_ansible/mainwin12.yml': line 19, column 9, but may\nbe
elsewhere in the file depending on the exact syntax problem.\n\nThe
offending line appears to be:\n\n\n - name: save m_size\n ^ here\n"}
I tried to put item in {{}}, "" or both, but it gave similar error messages.
Attempt 2:
- name: save m_size
set_fact:
list_ms: "{{win_pf.pagefiles}} + [{{item}}]"
with_sequence:
- start=0 end={{lista}}
or
- name: save m_size
set_fact:
list_ms: "{{win_pf.pagefiles}}"
with_sequence:
- start=0 end={{lista}}
Give:
TASK [show m_size]
*****************************************************************************************************************************************************************************
ok: [10.240.30.249] => { "list_ms": [ { "caption": "c:\\ 'pagefile.sys'",
"description": "'pagefile.sys' @ c:\\", "initial_size": 0, "maximum_size":
0, "name": "c:\\pagefile.sys" }, { "caption": "e:\\ 'pagefile.sys'",
"description": "'pagefile.sys' @ e:\\", "initial_size": 3583,
"maximum_size": 9133, "name": "e:\\pagefile.sys" }, 1 ] }
But the form
- name: save m_size
set_fact:
list_ms: "{{win_pf.pagefiles}} + [{{item}}] + {{.maximum_size}}"
with_sequence:
- start=0 end={{lista}}
Gives the error:
fatal: [10.240.30.249]: FAILED! => {"msg": "template error while templating
string: unexpected '.'. String: {{win_pf.pagefiles}} + [{{item}}] +
{{.maximum_size}}"}
Attempt 3:
#I tried without .maximum_size first, as in Attempt 2
- name: Show maximum_size
debug:
msg: "{{item}}"
with_sequence:
- start=0 end={{listapag}} format=win_pf.pagefiles[%1x]
Just gives:
TASK [Show maximum_size]
***********************************************************************************************************************************************************************
ok: [10.240.30.249] => (item=win_pf.pagefiles[0]) => { "msg":
"win_pf.pagefiles[0]" } ok: [10.240.30.249] => (item=win_pf.pagefiles[1])
=> { "msg": "win_pf.pagefiles[1]" }
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/70c1fee5-8ad5-4c18-a071-42dd7755530b%40googlegroups.com.