ansible - Ansible 如何遍历文件名以制作符号链接?
问题描述
这是我在 Ansible Play-Book 中的规范,用于制作符号链接:
---
- hosts: DEVSRV
become: yes
tasks:
- name: symlink deploy_config scripts
file:
src: "{{ item }}"
dest: "/usr/local/bin/"
state: link
loop:
- "/home/foo/bar/deploy/config/dev_deploy_config.sh"
- "/home/foo/bar/deploy/config/int_deploy_config.sh"
- "/home/foo/bar/deploy/config/prod_deploy_config.sh"
在src:
其中迭代loop:
其中好的路径和文件名。但是,如何在dest:
没有路径的情况下仅使用文件名?
解决方案
这个任务应该做到这一点,而且它非常不言自明:
- name: symlink deploy_config scripts
file:
src: "{{ item }}"
dest: "/usr/local/bin/{{ item.split('/') | last }}"
state: link
loop:
- "/home/foo/bar/deploy/config/dev_deploy_config.sh"
- "/home/foo/bar/deploy/config/int_deploy_config.sh"
- "/home/foo/bar/deploy/config/prod_deploy_config.sh"
希望能帮助到你!
推荐阅读
- terraform - 创建后无法获取 Terraform 实例 IP 地址
- python - PyTorch nn.Sequential 和 nn.ModuleList 有什么区别?
- postgresql - Geopandas to_postgis 需要几个小时
- import - 成功安装 conda 后无法导入 Geopandas
- reactjs - AdditionalProps = {} 是什么意思?
- php - 我正在构建一个 API,但在比较数组时遇到了问题
- flutter - SingleTickerProviderStateMixin AppBar 错误
- java - Wildfly 21 中 GET 请求查询参数中的管道字符 (|) 时出现“ERR_HTTP2_PROTOCOL_ERROR”
- paypal - 是否可以在不接触我的贝宝账户的情况下将资金从一个贝宝账户转移到另一个账户,但付款发生时我会收到通知?
- tensorflow - tensorflow.js 二维输入?