需求:
移动/iotdata/data/edge/ota-file-store/下的所有文件到/iotdata/data/edge/download/ota目录下,并删除旧目录
shell命令
mkdir -p /iotdata/data/edge/download/ota/; cp -r /iotdata/data/edge/ota-file-store/. /iotdata/data/edge/download/ota/;rm -rf /iotdata/data/edge/ota-file-store
shell脚本
#!/bin/bash
dest_dir="/iotdata/data/edge/download/ota"
src_dir="/iotdata/data/edge/ota-file-store"
if [ ! -d ${dest_dir} ]; then
mkdir -p ${dest_dir}
echo "新增文件夹/iotdata/data/edge/download/ota成功"
fi
if [ -d ${src_dir} ]&&[ -e ${src_dir} ]; then
cp -R ${src_dir}/. ${dest_dir}/
echo "复制原文件夹的固件到新文件夹成功"
fi
if [ -d ${src_dir} ]; then
rm -R ${src_dir}
echo "删除旧固件文件夹"
fi
ansible剧本
---
- hosts: all
tasks:
- name: create a new ota directory if it doesn't exist
file:
path: "{
{target_root_dir}}/data/edge/download/ota"
state: directory
- name: Check old ota file path exists
stat:
path: "/iotdata/data/edge/ota-file-store"
register: ota_file_store_stat
- name: move old ota files to new path
command: "cp -r /iotdata/data/edge/ota-file-store/. /iotdata//data/edge/download/ota/"
when: ota_file_store_stat.stat.exists
- name: Remove old ota file path
file:
path: "/iotdata/data/edge/ota-file-store"
state: absent
ignore_errors: yes
when: ota_file_store_stat.stat.exists