使用Ansible获取文件夹的排序列表 [英] Get sorted list of folders with Ansible
问题描述
我有 OS X"El capitan" 10.11.6 ,我正在使用 Ansible 2.1.1.0 在远程Linux服务器 Ubuntu 16.04 Xenial 上运行一些维护任务.我正在尝试获取在远程计算机(Linux)上排序的以下文件夹列表,以便可以在需要时删除旧的文件夹:
I have OS X "El capitan" 10.11.6 and I am using Ansible 2.1.1.0 to run some maintenance tasks on a remote Linux server Ubuntu 16.04 Xenial. I am trying to get the following list of folders sorted on the remote machine (Linux), so I can remove the old ones when needed:
/releases/0.0.0
/releases/0.0.1
/releases/0.0.10
/releases/1.0.0
/releases/1.0.5
/releases/2.0.0
我一直在尝试使用Ansible中的模块找到,但是它返回一个未排序列表.有没有简单的方法可以通过Ansible实现这一目标?
I have been trying with the module find in Ansible, but it returns a not sorted list. Is there an easy way to achieve this with Ansible?
推荐答案
有趣的解决方案,非常感谢.但是我想我已经在 Ubuntu 中找到了最简单的方法,只需使用ls -v /releases/
即可对所有文件夹进行自然排序:
Interesting solutions, thanks a lot guys. But I think I have found the easiest way in Ubuntu, just using ls -v /releases/
will apply natural sorting to all folders:
- name: List of releases in ascendent order
command: ls -v /releases/
register: releases
- debug: msg={{ releases.stdout_lines }}
响应为:
ok: [my.remote.com] => {
"msg": [
"0.0.0",
"0.0.1",
"0.0.10",
"1.0.0",
"1.0.5",
"2.0.0"
]
}
这篇关于使用Ansible获取文件夹的排序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!