Do I need a Jenkins slave on host2?
No, if you have Linux on host2
: you can simply run any command over SSH.
How can I use Server Groups Center in Jenkins pipeline to trigger Ansible on host2?
Server Groups Center
block comes from SSH2 Easy plugin, which is very old and doesn't support Jenkins pipeline. So you can't use information from that block of settings in your pipeline.
But there are other plugins for SSH; try Publish over SSH plugin for example. This plugin adds Publish over SSH
block to Jenkins Global Configuration
, where you can specify host2
connection parameters.
And then you can write pipeline step as follows ({HOST2}
is the name of host2
that you type in Publish over SSH
block in Jenkins Global Configuration
):
steps {
sshPublisher
failOnError: true,
publishers: [
sshPublisherDesc(
configName: "{HOST2}",
transfers: [
sshTransfer (execCommand: "ansible -m ping all -i inventory_file", execTimeout: 120000)
]
)
]
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…