pipeline { agent any stages { stage("copy playbook to ansible-server") { steps { script { echo "copying ansible folder to ansible server" } } } stage("copy ssh keys for Ansible") { steps { script { echo "copying ssh keys for ec2 instances" } } } stage("execute ansible playbook from the ansible-server") { steps { script { echo "executing ansible-playbook" def remote = [:] remote.name = "ansible-server" remote.host = "157.230.120.252" remote.user = "root" remote.allowAnyHosts = true withCredentials([sshUserPrivateKey(credentialsId: 'ansible-server-key', keyFileVariable: 'identity')]) { remote.identityFile = identity stage('Remote SSH') { sshCommand remote: remote, command: "ls -l" } } } } } } }