0
votes

The scenario is:

  • AWS Ec2 instances have two users, namely root and ubuntu. root is not advisable, but AWS recommends using ubuntu as the default user and this user has all sudo permissions.
  • Ansible's controlling machine runs on an Ec2 instance. The ansible playbook bootstraps another Ec2 instance and installs certain softwares on them.
  • Nodejs web app triggers this ansible scripts from root user.

    The setup works well when all the files for ansible and nodejs are kept in the same folder. But when organised in different folder, gives ansible ssh-error.

Error:

  • So, when organised in separate folders. The nodejs app triggers the ansible scripts. The new Ec2 instance is bootstrapped, but when the SSH-port is ready, cannot install the required softwares as it gives the ssh permission denied error.
  • The nodejs code that triggers the ansible scripts is executed as

      child.exec("ansible playbook ../playbook.yml");
    

    The only change in the code, after organising into folders is the addition of "../" path.

Debugging:

  • As i told you, there are two users in EC2 instance, the ec2-key module while bootstrapping stores the root's ssh-key to the newly bootstrapped instance. But, while installing the software on the newly bootstrapped instance, ubuntu's ssh=key is used for getting access. Thus, the conflicts with the keys give the ssh-permission denied error. And, this error particularly occurs after organising the ansible files and nodejs files into separate folders. If all the ansible and nodejs files are put inn the same folder, then no error is raised. FYI: All files are stored in the ubuntu user.

Just puzzled about this!! Thanks in advance.

1
Do you use a custom ansible.cfg? I think the only file which Ansible would use relative to the current working directory and not relative to the playbook is the ansible.cfg. So if one would be present in your ansible folder it would not be used if called from another working directory. For a solution, did you try to change the current working directory in your child process? child.exec("ansible playbook playbook.yml", {cwd: ".."}); - udondan
I haven't tried the {cwd: ""}. But I have a strong feel for the ansible.cfg. While organising the directories, let me try putting ansible.cfg alone in nodejs files. Will keep you updated about the progress. - Lakshman Diwaakar

1 Answers

0
votes

As said by @udondan, adding cwd to exec function works.