如何编写Ansible复制函数,将多个文件复制到多个JVM的目录中?

问题描述 投票:0回答:0

我在每个 RHEL 服务器上的 /etc/rc.d/init.d/ 目录中都有一个名为 JVMNAMES 的文件。它包含服务器上的 JVM 列表,每行都有一个新的 JVM 名称,如下所示。 abc-def01 bcd-efg02 cde-fgh01 等等……

我想循环复制4个.sh文件到每个JVM的bin目录下

我以前用这样的 shell 脚本完成过这个

LIST=/etc/rc.d/init.d/JVMNAMES

我在

cat $LIST

    do      
      echo "Updating the needed .sh files for JVM: '$i'..."
      cp /usr/apache/tomcat/tomcat-current/bin/catalina.sh /usr/apache/tomcat/$i/bin/
      cp /usr/apache/tomcat/tomcat-current/bin/version.sh /usr/apache/tomcat/$i/bin/
      cp /usr/apache/tomcat/tomcat-current/bin/startup.sh /usr/apache/tomcat/$i/bin/
      cp /usr/apache/tomcat/tomcat-current/bin/shutdown.sh /usr/apache/tomcat/$i/bin/
    done

到目前为止,这是我能想到的最好的。我花了很多时间在谷歌上搜索这个,但我还没有找到一个例子,所以我想我会发布它。有一个更好的方法吗?我还没有运行它,想从有这方面经验的人那里得到一些反馈,因为我们目前没有一个好的工作场所。

- name: Copy the needed .sh files to the bin directory of each JVM
  ansible.builtin.copy:
    src: "/usr/apache/tomcat/tomcat-current/bin/{{ item }}"
    dest: "/usr/apache/tomcat/{{ jvm_idx }}/bin/"
    owner: mwuser
    group: mwadmin
    mode: "u+rwx,g+rx,o=rx"
  with-items:
  - catalina.sh
  - version.sh
  - startup.sh
  - shutdown.sh
  loop: "{{ lookup('file', '/etc/rc.d/init.d/JVMNAMES') }}"
  loop_control:
    index_var: jvm_idx
for-loop ansible copy
© www.soinside.com 2019 - 2024. All rights reserved.