Does the find module stores the files by sorting based on modification time?

Does the find module stores the files by sorting based on modification time?

I have no idea, and the docs don't mention any sorting.
Even if the output was sorted I wouldn't rely on any sorting being
there in the future.
Instead, sort it yourself if you need that.
It will be more explicit and stable.
For example:

sorted_files: "{{ files|sort(attribute='mtime')

please help me

I installed ansible on mac os and installed vagrant server. After installation, when I run ansible -i hosts testserver -m ping -vvvv, it does not respond with the following message. I have not been able to solve the cause for a month.

ansible_host=127.0.0.1 | UNREACHABLE! => {

“changed”: false,

“msg”: “Failed to connect to the host via ssh: OpenSSH_8.1p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 47: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug1: Control socket "/Users/gimjeonghyeon/.ansible/cp/edc683342f" does not exist\r\ndebug2: resolving "ansible_host=127.0.0.1" port 2222\r\nssh: Could not resolve hostname ansible_host=127.0.0.1: nodename nor servname provided, or not known”,

“unreachable”: true

2021년 6월 30일 수요일 오후 10시 42분 53초 UTC+9에 dick…@geant.org님이 작성:

pls don't hijack existing/unrelated threads just because they're active...

Thanks, i’m able to sort it now by modification time.
Getting below error, though its working fine when it is hardcoded. Could you advise if something wrong with this approach?

ansible 2.9.21.

  • hosts: localhost
    gather_facts: 0
    tasks:

  • find:
    paths: /tmp
    register: op

  • debug: msg=“{{(op.files|sort(attribute=“mtime”))[0].path}}”

  • debug: msg=“{{(op.files|sort(attribute=“mtime”))[item].path}}”
    with_sequence: start=1 end=“{{op.files|length-1}}”

TASK [debug] ***********************************************************************************************************************************************************
ok: [localhost] => {
“msg”: “/tmp/comp2.yml”
}

TASK [debug] ***********************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘list object’ has no attribute ‘0’\n\nThe error appears to be in ‘/opt/ansible/find’: line 11, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n - debug: msg="{{(op.files|sort(attribute="mtime"))[0].path}}"\n - debug: msg="{{(op.files|sort(attribute="mtime"))[item].path}}"\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - "{{ foo }}"\n”}

I fixed it. Need to parse the items as int. so modified it to

  • debug: msg=“{{(op.files|sort(attribute=“mtime”))[item|int].path}}”
    with_sequence: start=0 end=“{{op.files|length-1}}”

Be that as it may, I don't see the need to fiddle with indexes, type
casting and length logic.
Just iterating over the list will give the same result:

    - debug: msg="{{ item.path }}"
      loop: "{{ op.files|sort(attribute='mtime') }}"