在角色执行期间为其他主机执行任务

时间:2019-06-04 14:23:52

标签: ansible

我尝试在主机上运行角色(Ansistrano),这很好:

VirtualService

我可以指定角色中包含的其他剧本:

extension String {

    /// Fetches a localized String
    ///
    /// - Returns: return value(String) for key
    public func localized() -> String {
        let path = Bundle.main.path(forResource: "en", ofType: "lproj")
        let bundle = Bundle(path: path!)
        return (bundle?.localizedString(forKey: self, value: nil, table: nil))!
    }


    /// Fetches a localised String Arguments
    ///
    /// - Parameter arguments: parameters to be added in a string
    /// - Returns: localized string
    public func localized(with arguments: [CVarArg]) -> String {
        return String(format: self.localized(), locale: nil, arguments: arguments)
    }

}

// variable in a class
 let tcAndPPMessage = "By_signing_up_or_logging_in,_you_agree_to_our"
                                     .localized(with: [tAndc, pp, signin])

// Localization File String
"By_signing_up_or_logging_in,_you_agree_to_our" = "By signing up or logging in, you agree to our \"%@\" and \"%@\" \nAlready have an Account? \"%@\"";

但是,现在我必须为另一个主机执行一个任务,这是角色执行期间本剧本的一部分。我 无法通过--- - name: perform role hosts: host_one roles: - ansistrano 实现。

ansistrano_specify_playbook: playbook.yml

因此,我想在此角色执行期间为另一台主机执行一项任务。由于无法编辑角色,因此无法使用import_playbook


编辑:

注意:在执行期间,第二台主机不在播放/清单中。因此- name: include task for other host import_playbook: other_host.yml 无效。

1 个答案:

答案 0 :(得分:0)

要将单个服务器委托给另一台主机,请使用delegate_to keyword

示例:

- name: include task for other host
  import_tasks: other_host_tasks.yml
  delegate_to: other_host

在这里,other_host必须是清单中该主机的inventory_hostname

更新
要将主机添加到播放过程中,请使用add_host module

或者,您可以操纵清单文件本身,然后使用meta: refresh_inventory模块。

相关问题