0

I am trying to Install RKE2 with Ansible.

but the command for installing RKE2 aren't apt commands

command for installing rke2 is

curl -sfL https://get.rke2.io |  INSTALL_RKE2_VERSION=v1.21.6+rke2r1 sh -

I have no idea how to convert this command into playbook code

I did checked other posts about curl - ansible but it doesn't help on my case

Kyroo0
  • 39
  • 1
  • 6
  • 1
    use module command. https://docs.ansible.com/ansible/latest/collections/ansible/builtin/command_module.html. you can use get_uri module for download script and execute after with command module. – Derioss Jan 25 '22 at 10:24
  • 2
    Mimicking a manual instruction set in Ansible is not the correct way. Use the dedicated modules instead. – β.εηοιτ.βε Jan 25 '22 at 10:31
  • @β.εηοιτ.βε command installing RKE2 is from RKE2 quick start guideline. but I should find another command to install RKE2. thanks – Kyroo0 Jan 25 '22 at 10:38
  • @Derioss I've watched documentation but it's still un understandable. but thanks for you help – Kyroo0 Jan 25 '22 at 10:38
  • Scrolling down to the end of the documentation page of a module typically provides you with examples: `ansible.builtin.command: cat /etc/mot`, as you can see it is executing shell commands. With a little adjustment you can take out the `cat /etc/mot` and replace it what you want the taks to do. In this case `curl -sfL https://get.rke2.io | INSTALL_RKE2_VERSION=v1.21.6+rke2r1 sh -` – user1098490 Jan 25 '22 at 10:51
  • @user1098490 thanks. I did tried using built in command but I failed. but thanks for your help – Kyroo0 Jan 25 '22 at 12:10

1 Answers1

4

Can this work ?

  vars:
    script_dir: mydir
  tasks:
  - file:
      state: directory
      path: "{{ script_dir }}"
  - name: download RKE2
    get_url:
      url: https://get.rke2.io
      validate_certs: false
      dest: "{{ script_dir }}/install.sh"
      mode: 0755
  - name: install RKE2
    command: "{{ script_dir }}/install.sh"
    environment:
      INSTALL_RKE2_VERSION: v1.21.6+rke2r1
Kwakou-Steve
  • 106
  • 2
  • It helpted a lot. This commnad helped me to install RKE2. I can try on next jobs. I really appreciate you help. I wanted to upvote you answer but I have no reputation. I wish you have a great day – Kyroo0 Jan 25 '22 at 12:11
  • 1
    Glad to have been of help. Have a great day, too. – Kwakou-Steve Jan 25 '22 at 12:41
  • 1
    @kyroo0 your upvote is recorded and will be given once you reach 50 reputation. Of this has changed you can still come back and do it in a few days. Accepting answers if they fix your issue (green tick) can be done whatever your reputation is. – Zeitounator Jan 26 '22 at 07:00
  • 1
    all tasks should be named but this code is fine, this answers is usefull – Derioss Jan 26 '22 at 11:26