Kai,
thanks for your explanation and I have made some progress but I am further
stopped by the next stage.
My problem is that I have a dynamic directory that generate log file in
certain directories with the following format
/var/log/app-YYYYMMDD-RANDOM_HASH/log_file_name-YYYYMMDDMMSS-[audit,console,access,].log
and I am trying to find all the logs in that directory that are more than
1GB then trim it.
I have these in my tasks
tasks:
#using the shell command because we need * expansion, otherwise if we
know the exact directory we can use command module instead
- name: list log directory to find wasabi main directory name
find:
paths: [ "/var/log/" ]
patterns: "wasabi-intuit-main*"
file_type: directory
register: out_directories
ignore_errors: True
- name: list log files for wasabi intuit main
find:
paths: "{{item.path}}"
patterns: "wasabi-intuit-main*.log"
file_type: file
register: out_files
with_items: "{{ out_directories.files }}"
ignore_errors: True
but it seems the returned out_files variable is a dict. the key is another
dict of the previous job and the value is a dict from find return values
with added properties like "changed","examined", and "msg". now I am
confused on how to iterate that object so I can filter the result.
I have tried "{{ out_files.values().files }}" and "{{
out_files.results.files }}" which does not seems to work
On Saturday, November 12, 2016 at 1:09:37 PM UTC-8, Kai Stian Olstad wrote:
>
> On 12. nov. 2016 02:25, Felix Gao wrote:
> > - hosts: test
> > remote_user: ec2-user
> > sudo: yes
> > tasks:
> > #using the shell command because we need * expansion, otherwise if
> we
> > know the exact directory we can use command module instead
> > - name: list log directory to find main directory name
> > find:
> > paths: [ "/var/log/" ]
> > patterns: "file-main*"
> > file_type: directory
> > register: out_directories
>
> When you use register with find the result is a list in files.
> You can check the content of out_directories with
> - debug: var=out_directories
>
> > - debug: var="{{ item }}"
>
> Var takes the variable and not the content of the variable, correct use
> is var=item.
>
> > with_items: "{{ out_directories }}"
>
> Register with find, the result is list of dictionaries in
> out_directories.files, so you'll need to write it like this
>
> - debug: var=item.path
> with_items: "{{ out_directories.files }}"
>
>
> --
> Kai Stian Olstad
>
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/d3f92fe0-c0eb-44e9-914a-49bbb071ee62%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.