I'm trying to install kubectl in my localhost using ansible, but i get the below error message:
fatal: [localhost]: FAILED! => {"changed": false, "dest": "/temp/", "msg": "An unknown error occurred: URL can't contain control characters. '/kubernetes-release/release/
curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt
/bin/linux/amd64/kubectl' (found at least ' ')", "state": "absent", "url": "https://storage.googleapis.com/kubernetes-release/release/curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt
/bin/linux/amd64/kubectl"}
I believe the issue might be with the back-tick characters in the url. I have tried surrounding them with single quotes and backslashes, but they didn't work. Here is my playbook:
- hosts: localhost
become: yes
tasks:
- name: install kubectl
get_url:
url: https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
dest: /usr/local/bin/
mode: '0440'
Get the result of curl into variable using 'shell' module, and reference it in the 'get_url' module:
- hosts: localhost
become: yes
tasks:
- name: get version
shell: curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt
register: version
- name: install kubectl
get_url:
url: "https://storage.googleapis.com/kubernetes-release/release/{{ version.stdout }}/bin/linux/amd64/kubectl"
dest: /usr/local/bin/
mode: '0440'