Linux 如何从Ansible输出中提取路径,并在我的剧本中的其他地方使用它?

Linux 如何从Ansible输出中提取路径,并在我的剧本中的其他地方使用它?,linux,bash,ansible,grep,output,Linux,Bash,Ansible,Grep,Output,我想从以下命令给出的输出中提取路径: 命令: /opt/myapp/dir/bin/client -a 8101 -h localhost -u user -p pass properties-global-export 输出: client: JAVA_HOME not set; results may vary Exporting file: org.fusesource.fabric.agent.properties Exporting file: local.app.node.vend

我想从以下命令给出的输出中提取路径:

命令:

/opt/myapp/dir/bin/client -a 8101 -h localhost -u user -p pass properties-global-export
输出:

client: JAVA_HOME not set; results may vary
Exporting file: org.fusesource.fabric.agent.properties
Exporting file: local.app.node.vendor.service4.properties
Exporting file: local.app.node.data.service3.properties
Exporting file: local.app.node.vendor.service1.properties
Exporting file: local.app.node.vendor.service2.properties
Files dumped into directory: /opt/myapp/install-node/node-2.1.11/data/properties-tmp
并使用
/opt/myapp/install node/node-2.1.11/data/properties tmp
路径在我的playbook中执行复制命令

- name: Export Properties File
  no_log: true
  shell: "{{ fuse_esb_client_dir }} -h localhost -a {{ karaf_port }} -u {{ karaf_user }} -p {{ karaf_pass }} properties-global-export | grep -o '\''/[^ ]*'\ "
  register: temp

- set_fact:
    tempPath: "{{ temp.stdout }}"

- name: All Files Exported To Path
  debug: var=temp.stdout

- name: Backup All Property Files to {{ backup_location }}
  command: cp -r "{{ tempPath }}" "{{ backup_location }}"
通过管道将输出传输到grep
grep-o'\'''/[^]*'\'\'\'
开始和结束处的额外
'\
用于转义playbook中的正则表达式字符。(如果要在cli中测试,请删除这些字符)

这给了我这个输出

/opt/myapp/install-node/node-2.1.11/data/properties-tmp
set\u fact
转储该输出,并在我的剧本中使用它。 希望有人会觉得这很有用。:)对像杰夫这样的职业选手也是如此:)请告诉我是否可以在我的剧本中改进任何东西

- name: Export Properties File
  no_log: true
  shell: "{{ fuse_esb_client_dir }} -h localhost -a {{ karaf_port }} -u {{ karaf_user }} -p {{ karaf_pass }} properties-global-export | grep -o '\''/[^ ]*'\ "
  register: temp

- set_fact:
    tempPath: "{{ temp.stdout }}"

- name: All Files Exported To Path
  debug: var=temp.stdout

- name: Backup All Property Files to {{ backup_location }}
  command: cp -r "{{ tempPath }}" "{{ backup_location }}"