用于远程复制和脚本执行的Ansible剧本

时间:2016-06-28 11:56:38

标签: shell ansible ansible-playbook

我希望在ansible中编写一个剧本,它将首先将我的包转移到远程主机,然后运行一个脚本。详细地说,让我说我在本地机器上有apache包,需要scp / rsync到远程节点A& B.然后我有我的脚本在A& amp; B两者,检查它是否已正确安装,然后仔细检查配置文件等。此脚本应仅在传输成功时运行。

编写了符合上述要求的以下剧本。请确认是否需要进一步改进。提前谢谢!

剧本:

---
 - hosts: droplets
   remote_user: root

   tasks:

    - name: Copy package to target machines
      synchronize: src=/home/luckee/apache.rpm dest=/var/tmp/

    - name: Run installation and verification script
      script: /home/luckee/apache_install.sh
      register: result

    - name: Show result
      debug: msg="{{ result.stdout }}"
...

1 个答案:

答案 0 :(得分:1)

这样安装脚本只有在复制任务发生变化(在流程中执行)并成功退出时才会运行:

Reveal.addEventListener('slidechanged', function(event) {
    if ($(event.currentSlide).hasClass('video-stepper')) {
        // When we enter a slide with a step-by-step video, we stop reveal.js
        //  from doing anything. Below, we define our own keystroke handler.
        Reveal.removeEventListeners();

        // Set the width and height of the video so that it fills the slide.
        var stretcher = $(event.currentSlide).find('video.placeholder').get(0);
        var video = $(event.currentSlide).find('video.video-step').get(0);
        video.setAttribute('width', stretcher.getAttribute('width'));
        video.setAttribute('height', stretcher.getAttribute('height'));

        // Convert the data-sources attribute to an array of strings. We will
        // iterate through the array with current_video_index.
        var sources = JSON.parse(video.getAttribute('data-sources'));
        var current_video_index = 0;

        // Add a <source> element to the video and set the 'src' to
        // the first video.
        var source = document.createElement('source');
        source.setAttribute('src', sources[0]);
        video.appendChild(source);

        document.addEventListener('keydown', function step_through_videos(event) {
            if (event.which == 39) {
                // right arrow key: show next video

                // For the next video, create a new <video> element
                // and place it on top of the old <video> element.
                // Then load and play the new. This avoids flickering.
                var new_video = $(video).clone().get(0);
                var new_video_source = $(new_video).children('source').get(0);
                new_video_source.src = sources[current_video_index];
                new_video.load();
                $(new_video).addClass('front video-step');
                $(new_video).insertAfter(video);
                new_video.play();

                // Wait a little before removing the old video.
                new Promise((resolve) => setTimeout(resolve, 500)).then(function() {
                    video.remove();
                    video = new_video;
                    $(video).removeClass('front');
                });

                current_video_index = current_video_index + 1;

                event.preventDefault();
            } else if (event.which == 37) {
                // left arrow key: return the counter to previous video
                current_video_index = current_video_index - 1;

                event.preventDefault();
            }

            if (0 > current_video_index || current_video_index >= sources.length) {
                // Reinstall reveal.js handlers.

                document.removeEventListener('keydown', step_through_videos, true);
                Reveal.addEventListeners();
                console.log('Added reveal.js event listeners.');
            }
        }, true);
    }
});