I am trying to join in some of my kubernetes nodes to the cluster however the shell script used by the user marlon requires privilege escalation which then is not finding the file's location
both nodes have copied the file correctly to tmp folder by the playbook
marlon@node1:/tmp$ ll join-command.sh
-rwxrwxrwx 1 marlon marlon 169 Oct 1 09:40 join-command.sh*
marlon@node2:/tmp$ ll join-command.sh
-rwxrwxrwx 1 marlon marlon 169 Oct 1 09:41 join-command.sh*
however whenever trying to run the playbook with the correct privileges I am getting the following error:
TASK [kubernetes : Join the node to cluster] *************************************************************************************************************************************************************
fatal: [node1.madebeen.com]: FAILED! => {"changed": true, "cmd": "./tmp/join-command.sh", "delta": "0:00:00.002299", "end": "2021-10-01 09:40:50.377483", "msg": "non-zero return code", "rc": 127, "start": "2021-10-01 09:40:50.375184", "stderr": "/bin/sh: 1: ./tmp/join-command.sh: not found", "stderr_lines": ["/bin/sh: 1: ./tmp/join-command.sh: not found"], "stdout": "", "stdout_lines": []}
fatal: [node2.madebeen.com]: FAILED! => {"changed": true, "cmd": "./tmp/join-command.sh", "delta": "0:00:00.003164", "end": "2021-10-01 09:40:50.394857", "msg": "non-zero return code", "rc": 127, "start": "2021-10-01 09:40:50.391693", "stderr": "/bin/sh: 1: ./tmp/join-command.sh: not found", "stderr_lines": ["/bin/sh: 1: ./tmp/join-command.sh: not found"], "stdout": "", "stdout_lines": []}
here is the playbook's configuration:
- name: Copy the join command to server location
become_user: marlon
copy: src=join-command dest=/tmp/join-command.sh mode=0777
- name: Join the node to cluster
become_method: su
become_user: marlon
shell: ./tmp/join-command.sh
I've also tried to set become: yes but then the privileged user (root) couldn't find the file...
fatal: [node1.madebeen.com]: FAILED! => {"changed": true, "cmd": "./tmp/join-command.sh", "delta": "0:00:00.002299", "end": "2021-10-01 09:45:50.377483", "msg": "non-zero return code", "rc": 127, "start": "2021-10-01 09:40:50.375184", "stderr": "/bin/sh: 1: ./tmp/join-command.sh: not found", "stderr_lines": ["/bin/sh: 1: ./tmp/join-command.sh: not found"], "stdout": "", "stdout_lines": []}
fatal
I also tried to use command: sh ./tmp/join-command.sh
fatal: [node1.madebeen.com]: FAILED! => {"changed": true, "cmd": ["sh", "./tmp/join-command.sh"], "delta": "0:00:00.001923", "end": "2021-10-01 09:54:05.662220", "msg": "non-zero return code", "rc": 127, "start": "2021-10-01 09:54:05.660297", "stderr": "sh: 0: Can't open ./tmp/join-command.sh", "stderr_lines": ["sh: 0: Can't open ./tmp/join-command.sh"], "stdout": "", "stdout_lines": []}
fatal: [node2.madebeen.com]: FAILED! => {"changed": true, "cmd": ["sh", "./tmp/join-command.sh"], "delta": "0:00:00.001988", "end": "2021-10-01 09:54:05.683108", "msg": "non-zero return code", "rc": 127, "start": "2021-10-01 09:54:05.681120", "stderr": "sh: 0: Can't open ./tmp/join-command.sh", "stderr_lines": ["sh: 0: Can't open ./tmp/join-command.sh"], "stdout": "", "stdout_lines": []}
and didn't work either
fatal: [node1.madebeen.com]: FAILED! => {"changed": true, "cmd": ["sh", "./tmp/join-command.sh"], "delta": "0:00:00.001923", "end": "2021-10-01 09:54:05.662220", "msg": "non-zero return code", "rc": 127, "start": "2021-10-01 09:54:05.660297", "stderr": "sh: 0: Can't open ./tmp/join-command.sh", "stderr_lines": ["sh: 0: Can't open ./tmp/join-command.sh"], "stdout": "", "stdout_lines": []}
fatal: [node2.madebeen.com]: FAILED! => {"changed": true, "cmd": ["sh", "./tmp/join-command.sh"], "delta": "0:00:00.001988", "end": "2021-10-01 09:54:05.683108", "msg": "non-zero return code", "rc": 127, "start": "2021-10-01 09:54:05.681120", "stderr": "sh: 0: Can't open ./tmp/join-command.sh", "stderr_lines": ["sh: 0: Can't open ./tmp/join-command.sh"], "stdout": "", "stdout_lines": []}
went through several other threads on this but couldn't find a definitive answer on it... any thoughts?
I have also tried to remove the . in front of the directory but still didn't work out... #middlewareinventory.com/blog/…
- name: Join the node to cluster
#become_user: marlon
#become_method:
sudo become: yes
shell: /tmp/join-command.sh
I think the issue is here
shell: ./tmp/join-command.sh
You are using a relative path, that's why it can not be found. You should use a full path. try
shell: /tmp/join-command.sh
https://www.geeksforgeeks.org/absolute-relative-pathnames-unix/
Got it work with the following:
https://www.middlewareinventory.com/blog/ansible-sudo-ansible-become-example/
- name: Join the node to cluster
#become_user: marlon
#become_method: sudo
#become: yes
shell: |
kubeadm reset --force
/tmp/join-command.sh