gpt4 book ai didi

ansible - 将文件从 ansible 中的相对路径复制到服务器

转载 作者:行者123 更新时间:2023-12-03 14:00:59 25 4
gpt4 key购买 nike

如何传递相对路径,以便 Ansible 可以从 node/keys 复制文件并将它们复制到服务器?
剧本是ansible/playbook .
我的目录结构是:

├── ansible
│   ├── inventory
│   └── playbook
├── node
│   ├── keys
│   ├── index.js
│   ├── node_modules
│   ├── package-lock.json
│   └── utils
└── shell
├── data.json
├── create-data.sh
├── destory.sh
└── firewall-rules.sh
下面是剧本:
- hosts: all
vars:
source: "{{ source }}"
destination: /home/ubuntu

tasks:

- name: Copy files
copy:
src: "{{ source }}"
dest: "{{ destination }}"
这就是我运行的方式:
ansible-playbook -i inventory/inventory.yaml playbook/crypto-generate.yaml
--extra-vars "source=../node/keys"
我正在尝试传递相对路径。

最佳答案

您可以在 src 中使用绝对路径,以避免不知道根文件夹在哪里的问题。

Local path to a file to copy to the remote server. This can be absolute or relative. If path is a directory, it is copied recursively. In this case, if path ends with "/", only inside contents of that directory are copied to destination. Otherwise, if it does not end with "/", the directory itself with all contents is copied. This behavior is similar to the rsync command line tool.



https://docs.ansible.com/ansible/latest/modules/copy_module.html

关于ansible - 将文件从 ansible 中的相对路径复制到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57888312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com