I'm including the playbook below, followed by the relevant output. I have redacted the real data values with dummy values, but it should give you an idea of what I'm trying and what I'm getting.
body: "{\"method\": \"user_find/1\",\"params\": [[],{\"version\": \"{{ api_vers }}\"}]}"
no_log: true
register: user_find
- name: Set fact for users
set_fact:
uid: "{{ user_find.json.result.result|map(attribute='uid')|flatten }}"
users: "{{ user_show.results|json_query('[*].json.result.result.uid[0]')|flatten }}"
pwdexp: "{{ user_show.results|json_query('[*].json.result.result.krbpasswordexpiration[0]')|flatten }}"
debug:
msg: "{{ users }}"
- name: Print pwdexp fact
debug:
msg: "{{ pwdexp }}"
- name: Set userlist fact
set_fact:
userlist: "{{ item.0 }} {{ item.1 }} {{ (ansible_date_time.epoch|int - ((item.1['__datetime__'] | to_datetime('%Y%m%d%H%M%SZ')).strftime('%s'))|int) / (60*60*24) }}"
with_together:
- "{{ users }}"
- "{{ pwdexp }}"
- name: Print userlist fact
debug:
msg: "{{ userlist }}"
The output is as follows:
TASK [Print users fact] ***********************************************************************************************************
ok: [
ipaserver.example.com] => {
"msg": [
"test.user1",
"test.user2"
]
}
TASK [Print pwdexp fact] **********************************************************************************************************
ok: [
ipaserver.example.com] => {
"msg": [
{
"__datetime__": "20220103195934Z"
},
{
"__datetime__": "20200218151047Z"
}
]
}
TASK [Print user_show variable] ***************************************************************************************************
ok: [
ipaserver.example.com] => {
"msg": {
"changed": false,
"msg": "All items completed",
"results": [
{
"ansible_loop_var": "item",
"cache_control": "no-cache, private",
"changed": false,
"connection": "close",
"content_length": "1681",
"content_security_policy": "frame-ancestors 'none'",
"content_type": "application/json; charset=utf-8",
"cookies": {},
"cookies_string": "",
"date": "Fri, 10 Dec 2021 12:49:38 GMT",
"elapsed": 0,
"failed": false,
"invocation": {
"module_args": {
"attributes": null,
"backup": null,
"body": {
"method": "user_show",
"params": [
[
"test.user1"
],
{
"all": true,
"version": "2.237"
}
]
},
"body_format": "json",
"client_cert": null,
"client_key": null,
"content": null,
"creates": null,
"delimiter": null,
"dest": null,
"directory_mode": null,
"follow": false,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {
"Accept": "application/json",
"Content-Type": "application/json",
"Cookie": "ipa_session=MagBearerToken=qaKkpuAqhB0hUfPPxewHikiD9j5wrInFi2%2b2AV%2bALxA8HHy28j5ajQUaZN%2fQj%2bnfvrZJFOYm4K9oLbw2jTWiVJ2DM1ZeKliRdy5IUCZm15DVfYmwVo8fFZQGdlamH9zS9MuuHYCx2cCkdCbaFO7UEpxceTfoa65l1Uu0KmUH4LD%2bY5ipyUnh7I2jcvviztT5wBmGWVEhTgvNSshtKoWPEg%3d%3d;path=/ipa;httponly;secure;",
"Referer": "
https://ipaserver.example.com/ipa"
},
"http_agent": "ansible-httpget",
"method": "POST",
"mode": null,
"owner": null,
"regexp": null,
"remote_src": null,
"removes": null,
"return_content": false,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 30,
"unix_socket": null,
"unsafe_writes": false,
"url": "
https://ipaserver.example.com/ipa/session/json",
"url_password": null,
"url_username": null,
"use_proxy": true,
"validate_certs": true
}
},
"item": "0",
"json": {
"error": null,
"id": null,
"principal": "
ad...@EXAMPLE.COM",
"result": {
"result": {
"cn": [
"Test User1"
],
"displayname": [
"Test User1"
],
"dn": "uid=test.user1,cn=users,cn=accounts,dc=example,dc=com",
"gecos": [
"Test User1"
],
"gidnumber": [
"10000"
],
"givenname": [
"Test"
],
"has_keytab": true,
"has_password": true,
"homedirectory": [
"/home/test.user1"
],
"initials": [
"TU"
],
"ipauniqueid": [
"8982f708-d556-11e9-8432-001a4a160181"
],
"ipauserauthtype": [
"password"
],
"krbcanonicalname": [
"
test....@EXAMPLE.COM"
],
"krbextradata": [
{
"__base64__": "AAKmrlxhcm9vdC9hZG1pbkBTRUNVUkUtT1NFLkZBQS5HT1YA"
}
],
"krblastfailedauth": [
{
"__datetime__": "20211005195828Z"
}
],
"krblastpwdchange": [
{
"__datetime__": "20211005195934Z"
}
],
"krblastsuccessfulauth": [
{
"__datetime__": "20211122212918Z"
}
],
"krbloginfailedcount": [
"0"
],
"krbpasswordexpiration": [
{
"__datetime__": "20220103195934Z"
}
],
"krbprincipalname": [
"
test....@EXAMPLE.COM"
],
"loginshell": [
"/bin/bash"
],
"mail": [
"
test....@example.com"
],
"memberof_group": [
"ipausers"
],
"memberofindirect_group": [
"folderaccess"
],
"nsaccountlock": false,
"objectclass": [
"ipasshgroupofpubkeys",
"krbticketpolicyaux",
"ipaobject",
"organizationalperson",
"top",
"ipasshuser",
"inetorgperson",
"person",
"ipauserauthtypeclass",
"inetuser",
"krbprincipalaux",
"posixaccount"
],
"preserved": false,
"sn": [
"User"
],
"telephonenumber": [
"(xxx) yyy-zzzz"
],
"uid": [
"test.user1"
],
"uidnumber": [
"1000"
]
},
"summary": null,
"value": "test.user1"
},
"version": "4.6.8"
},
"msg": "OK (1681 bytes)",
"redirected": false,
"server": "Apache/2.4.6 (Red Hat Enterprise Linux) mod_auth_gssapi/1.5.1 mod_nss/1.0.14 NSS/3.28.4 mod_wsgi/3.4 Python/2.7.5",
"status": 200,
"url": "
https://ipaserver.example.com/ipa/session/json",
"vary": "Accept-Encoding",
"x_frame_options": "DENY"
},
{
"ansible_loop_var": "item",
"cache_control": "no-cache, private",
"changed": false,
"connection": "close",
"content_length": "1368",
"content_security_policy": "frame-ancestors 'none'",
"content_type": "application/json; charset=utf-8",
"cookies": {},
"cookies_string": "",
"date": "Fri, 10 Dec 2021 12:49:40 GMT",
"elapsed": 0,
"failed": false,
"invocation": {
"module_args": {
"attributes": null,
"backup": null,
"body": {
"method": "user_show",
"params": [
[
"test.user2"
],
{
"all": true,
"version": "2.237"
}
]
},
"body_format": "json",
"client_cert": null,
"client_key": null,
"content": null,
"creates": null,
"delimiter": null,
"dest": null,
"directory_mode": null,
"follow": false,
"follow_redirects": "safe",
"force": false,
"force_basic_auth": false,
"group": null,
"headers": {
"Accept": "application/json",
"Content-Type": "application/json",
"Cookie": "ipa_session=MagBearerToken=qaKkpuAqhB0hUfPPxewHikiD9j5wrInFi2%2b2AV%2bALxA8HHy28j5ajQUaZN%2fQj%2bnfvrZJFOYm4K9oLbw2jTWiVJ2DM1ZeKliRdy5IUCZm15DVfYmwVo8fFZQGdlamH9zS9MuuHYCx2cCkdCbaFO7UEpxceTfoa65l1Uu0KmUH4LD%2bY5ipyUnh7I2jcvviztT5wBmGWVEhTgvNSshtKoWPEg%3d%3d;path=/ipa;httponly;secure;",
"Referer": "
https://ipaserver.example.com/ipa"
},
"http_agent": "ansible-httpget",
"method": "POST",
"mode": null,
"owner": null,
"regexp": null,
"remote_src": null,
"removes": null,
"return_content": false,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"status_code": [
200
],
"timeout": 30,
"unix_socket": null,
"unsafe_writes": false,
"url": "
https://ipaserver.example.com/ipa/session/json",
"url_password": null,
"url_username": null,
"use_proxy": true,
"validate_certs": true
}
},
"item": "1",
"json": {
"error": null,
"id": null,
"principal": "
ad...@EXAMPLE.COM",
"result": {
"result": {
"cn": [
"Test User2"
],
"displayname": [
"Test User2"
],
"dn": "uid=test.user2,cn=users,cn=accounts,dc=example,dc=com",
"gecos": [
"Test User2"
],
"gidnumber": [
"10000"
],
"givenname": [
"Test"
],
"has_keytab": true,
"has_password": true,
"homedirectory": [
"/home/test.user2"
],
"initials": [
"TU"
],
"ipauniqueid": [
"60fe8b86-5282-11ea-ac93-001a4a160181"
],
"krbcanonicalname": [
"
test....@EXAMPLE.COM"
],
"krbextradata": [
{
"__base64__": "AAK6Nkxecm9vdC9hZG1pbkBTRUNVUkUtT1NFLkZBQS5HT1YA"
}
],
"krbpasswordexpiration": [
{
"__datetime__": "20200218151047Z"
}
],
"krbprincipalname": [
"
test....@EXAMPLE.COM"
],
"loginshell": [
"/bin/bash"
],
"mail": [
"
test....@example.com"
],
"memberof_group": [
"ipausers"
],
"memberofindirect_group": [
"folderaccess"
],
"nsaccountlock": true,
"objectclass": [
"top",
"person",
"organizationalperson",
"inetorgperson",
"inetuser",
"posixaccount",
"krbprincipalaux",
"krbticketpolicyaux",
"ipaobject",
"ipasshuser",
"ipaSshGroupOfPubKeys"
],
"preserved": false,
"sn": [
"User"
],
"telephonenumber": [
"(xxx)yyy-zzzz"
],
"uid": [
"test.user2"
],
"uidnumber": [
"1100"
]
},
"summary": null,
"value": "test.user2"
},
"version": "4.6.8"
},
"msg": "OK (1368 bytes)",
"redirected": false,
"server": "Apache/2.4.6 (Red Hat Enterprise Linux) mod_auth_gssapi/1.5.1 mod_nss/1.0.14 NSS/3.28.4 mod_wsgi/3.4 Python/2.7.5",
"status": 200,
"url": "
https://ipaserver.example.com/ipa/session/json",
"vary": "Accept-Encoding",
"x_frame_options": "DENY"
}
]
}
}
TASK [Set userlist fact] **********************************************************************************************************
ok: [
ipaserver.example.com] => (item=[u'test.user1', {u'__datetime__': u'20220103195934Z'}])
ok: [
ipaserver.example.com] => (item=[u'test.user2', {u'__datetime__': u'20200218151047Z'}])
TASK [Print userlist fact] ********************************************************************************************************
ok: [
ipaserver.example.com] => {
"msg": "test.user2 {u'__datetime__': u'20200218151047Z'} 660.693483796"
}
PLAY RECAP ************************************************************************************************************************
ipaserver.example.com : ok=12 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0