使用 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 中的模块 find,但它返回一个未排序列表.是否有使用 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屋!