Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-72445

ENV vars supplied IP address are treated as DNS names

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Trivial Trivial
    • ssh-steps-plugin
    • None
    • Jenkins Container: v2.387.3
      SSH-Step: v2.0.68.va_d21a_12a_6476

      Passing IP address from Terraform
      env.ANSIBLE_SERVER_IP = sh(
      script: 'terraform output ec2_public_ip-ansible-control-node',
      returnStdout: true
      ).trim()
      For the sake of conversation lets say this will be 999.999.999.999 (I know this is not a real IP),
      if we echo "${env.ANSIBLE_SERVER_IP}" this spit out an output of "999.999.999.999".
       
      Then we call the following step in the pipeline
      echo "calling ansbile playbook to configure ec2 instances"
      def ansible_node = [:]
      ansible_node.name = "ansible-control-node"
      ansible_node.host = "${env.ANSIBLE_SERVER_IP}"
      ansible_node.allowAnyHosts = true // Equivalent to StrictHostKeyChecking=no

      withCredentials([sshUserPrivateKey(credentialsId: 'ansible-ssh-key', keyFileVariable: 'keyfile', usernameVariable: 'user')]) {
      ansible_node.user = user
      ansible_node.identityFile = keyfile
      echo "Running commands / scripts remotely on Ansible Server."
      sshCommand remote: ansible_node, command: 'ls -la', sudo: false
       
      The sshCommand will fail to execute with the following error message
      [Pipeline] // node
      [Pipeline] End of Pipeline
      java.net.UnknownHostException: "999.999.999.999"
          at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:229)
          at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
          at java.base/java.net.Socket.connect(Socket.java:609)
          at java.base/java.net.Socket.connect(Socket.java:558)

       
      I have also tried the following and fail.
      ansible_node.host = '${env.ANSIBLE_SERVER_IP}'
      ansible_node.
      host = "$ANSIBLE_SERVER_IP"
      ansible_node.
      host = '$ANSIBLE_SERVER_IP'
       
      However, if we manually update the code to below, the step succeeds.

      ansible_node.host = "999.999.999.999"
       
      As of now, the resolution I have is to manually remove the " character on the resulting string, as in

      ansible_node.host = env.ANSIBLE_SERVER_IP.toString().replace("\"", "")

            nrayapati Naresh Rayapati
            sheenlim08 Sheen Ismhael
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: