Ansible移动文件
Ansible moving files
我正在创建一个角色来部署 Jira 实例。我的问题是,如何将文件从一个目录移动到另一个目录,我正在尝试这样的事情:
- name: Create Jira installation directory
command: mv "/tmp/atlassian-jira-software-{{ jira_version }}-standalone/*" "{{ installation_directory }}"
when: not is_jira_installed.stat.exists
但是不行,我想将所有文件从一个目录复制到另一个目录而不复制目录。
来自 the synopsis of the command
module:
The command(s) will not be processed through the shell, so variables like $HOSTNAME
and operations like "*"
, "<"
, ">"
, "|"
, ";"
and "&"
will not work. Use the ansible.builtin.shell module if you need these features.
所以,您的问题是 command
模块没有扩展通配符 *
,如您所料,您应该改用 shell
模块:
- name: Create Jira installation directory
shell: "mv /tmp/atlassian-jira-software-{{ jira_version }}-standalone/* {{ installation_directory }}"
when: not is_jira_installed.stat.exists
现在,请注意,您也可以通过使用 copy
module.
- copy:
src: "/tmp/atlassian-jira-software-{{ jira_version }}-standalone/"
dest: "{{ installation_directory }}"
remote_src: yes
我正在创建一个角色来部署 Jira 实例。我的问题是,如何将文件从一个目录移动到另一个目录,我正在尝试这样的事情:
- name: Create Jira installation directory
command: mv "/tmp/atlassian-jira-software-{{ jira_version }}-standalone/*" "{{ installation_directory }}"
when: not is_jira_installed.stat.exists
但是不行,我想将所有文件从一个目录复制到另一个目录而不复制目录。
来自 the synopsis of the command
module:
The command(s) will not be processed through the shell, so variables like
$HOSTNAME
and operations like"*"
,"<"
,">"
,"|"
,";"
and"&"
will not work. Use the ansible.builtin.shell module if you need these features.
所以,您的问题是 command
模块没有扩展通配符 *
,如您所料,您应该改用 shell
模块:
- name: Create Jira installation directory
shell: "mv /tmp/atlassian-jira-software-{{ jira_version }}-standalone/* {{ installation_directory }}"
when: not is_jira_installed.stat.exists
现在,请注意,您也可以通过使用 copy
module.
- copy:
src: "/tmp/atlassian-jira-software-{{ jira_version }}-standalone/"
dest: "{{ installation_directory }}"
remote_src: yes