Reputation: 3065
My Jenkins is on host1 and I wish to trigger ansible which is on host2 using Jenkins pipeline. This can be done by creating a slave node on host2 and specifying agent
in Jenkins pipeline.
However, I do not have a Jenkins slave on host2.
Instead, Jenkins has connectivity to host2 by means of Server Groups Center
which can be found under Jenkins Global Configuration
Do I need a Jenkins slave on host2 ? If not, then how can I use Server Groups Center
in Jenkins pipeline to trigger Ansible on host2? Sample code please…
Upvotes: 0
Views: 1168
Reputation: 1123
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) \
] \
) \
]
}
Upvotes: 1