title: Can I execute an ansible playbook inside a playbook?
body: <p>I am running a playbook to provision my master, and after that I want to provision my nodes that are only accessible from the master.</p>
  
  <p>If I try to execute the ansible-playbook from a task of the main playbook, the connection is refused, but if I ssh login inside the master and run the same ansible-playbook command all works fine</p>
  
  <p>This is the main ansible-playbook, all tasks are executed untill it arrives the last</p>
  
  <pre><code>    - name: "Copy private key to Workstation"
        copy:
          src: ~/.ssh/private.pem
          dest: /home/ubuntu/.ssh/id_rsa
          mode: 0400
  
      - name: "Executing playbookNodes on Workstation"
        shell: "sudo ansible-playbook -i /home/ubuntu/inventory.yaml playbookNodes.yaml"
        tags:
          - remote_playbook
  </code></pre>
  
  <p>If I run the above code I get:</p>
  
  <pre><code>fatal: [workstation]: FAILED! =&gt; {
      "changed": true,
      "cmd": "ssh ubuntu@12.0.11.10",
      "delta": "0:00:00.065269",
      "end": "2019-07-22 16:05:31.183599",
      "invocation": {
          "module_args": {
              "_raw_params": "ssh ubuntu@12.0.11.10",
              "_uses_shell": true,
              "argv": null,
              "chdir": null,
              "creates": null,
              "executable": null,
              "removes": null,
              "stdin": null,
              "warn": true
          }
      },
      "msg": "non-zero return code",
      "rc": 255,
      "start": "2019-07-22 16:05:31.118330",
      "stderr": "Warning: Permanently added '12.0.11.10' (ECDSA) to the list of known hosts.\r\nubuntu@12.0.11.10: Permission denied (publickey).",
      "stderr_lines": [
          "Warning: Permanently added '12.0.11.10' (ECDSA) to the list of known hosts.",
          "ubuntu@12.0.11.10: Permission denied (publickey)."
      ],
      "stdout": "",
      "stdout_lines": []
  }
  </code></pre>
  
  <p>but works when I run <code>ssh -i private.pem ubuntu@master</code> and inside the master <code>ansible-playbook -i inventory.yaml playbookNodes.yaml</code></p>