Hi All,
I'm new here and have an issue that gives me a headache ;-)
I'm pretty new to ansible although I did the RH294 course.
Here's my playbook:
---
- name: count files and get oldest file
hosts: all
vars:
- tomcat_home_dir: /data/tmp
- folder_path: temp
tasks:
- name: Find how many tomcat instances we have
find:
paths: "{{ tomcat_home_dir }}"
patterns: "tomcat*"
recurse: no
excludes: "tomcat"
file_type: directory
register: tmp_tomcat_dirs
- name: debug
debug:
msg: "{{ tmp_tomcat_dirs.matched }}"
- name: find files
find:
paths: "{{ tomcat_home_dir }}/tomcat{{ item }}/{{ folder_path }}"
age: 90d
recurse: yes
with_sequence: start=1 end={{ tmp_tomcat_dirs.matched }}
register: find_result
- name: result
debug:
msg: "{{ find_result.matched }}"
which results in an error:
TASK [result]
**************************************************************************************************************************************************************************************************
Thursday 25 March 2021 14:42:43 +0100 (0:00:02.455) 0:00:09.868
********
fatal: [tstcgttoml01]: FAILED! => {"msg": "The task includes an option with
an undefined variable. The error was: 'dict object' has no attribute
'matched'\n\nThe error appears to have been in
'/home/people/cginkel/automation_projects/playbooks/check_tmp_folder_tomcat/playbook.yml':
line 30, column 7, but may\nbe elsewhere in the file depending on the exact
syntax problem.\n\nThe offending line appears to be:\n\n\n - name:
result\n ^ here\n"}
I understand the error, but why can't I use .matched all of a sudden?
If I run it without anything or just with .results it will give a list with
all information about the files it finds. How do I get the attribute
matched out of that?
here's an example list:
{
"_ansible_ignore_errors": null,
"_ansible_item_label": "3",
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": false,
"examined": 4,
"failed": false,
"files": [],
"invocation": {
"module_args": {
"age": "90d",
"age_stamp": "mtime",
"contains": null,
"depth": null,
"excludes": null,
"file_type": "file",
"follow": false,
"get_checksum": false,
"hidden": false,
"paths": [
"/data/tmp/tomcat3/temp"
],
"patterns": [
"*"
],
"recurse": true,
"size": null,
"use_regex": false
}
},
"item": "3",
"matched": 0,
"msg": ""
Also, I am on version 2.6.6 and python 2.6.6 and can't use the map or
selectattr filters.... which is a bummer, but it's a production machine I
can't just upgrade.
The must be an easy way, but I spend hours reading the docs and forums.
Any help would be appreciated. If I can get around it without the
with_sequence I would be glad to hear it on how to do this
With kind regards,
Cornelis
--
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/953c457e-bfff-4d21-aeb5-6a9b0f7ed9a5n%40googlegroups.com.