【问题标题】:Ansible how to run all tasks on localhost except one on remote serverAnsible如何在本地主机上运行所有任务,除了远程服务器上的一个
【发布时间】:2022-07-23 05:10:19
【问题描述】:

我有一个在loacalhost 上运行多个任务的剧本,如下所示,除了我需要将结果存储在文件中到远程服务器并在下一个任务中使用它作为基于文件内容的条件.

最好的方法是什么?我们如何为这个服务器定义凭据?

- hosts: localhost
  tasks:
    - name: run task1
      debug: msg="running task on localhost"
    - name: run task 2
      debug: msg="running all others also localhost"
      register: output
    - name: store output in remote storage server
      debug: msg="Copy the content of register output to a file in remote server"
      delegate_to:  "remote.storageserver.com"

【问题讨论】:

    标签: ansible devops


    【解决方案1】:

    进行两次播放,并在第一次播放结束时设置远程主机上的任务所需的变量。将hosts 设置为仅localhost 用于第一次播放,remotehost 用于第二次播放。在第二场比赛中包括您需要的任何远程任务。您也可以通过这种方式定义不同的凭据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-03
      • 1970-01-01
      相关资源
      最近更新 更多