8

Setting up VSCode for Ansible Lightspeed AI in Ubuntu 22.04 desktop

 8 months ago
source link: https://www.cyberciti.biz/programming/howto-setting-up-vscode-for-ansible-lightspeed-ai-in-ubuntu-22-04-desktop/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Setting up VSCode for Ansible Lightspeed AI in Ubuntu 22.04 desktop

Red Hat launched the Ansible Lightspeed Code Assistant Generative AI with IBM Watson Code Assistant in May 2023. This preview is now available to all Ansible users, allowing them to explore the technology, provide feedback to Red Hat, and further train the AI model. In this brief blog post, I will share my personal experience with installing and utilizing Ansible Lightspeed AI to create playbooks in VSCode using Ubuntu Linux 20.04 LTS desktop.

nixCraft: Privacy First, Reader Supported
  • nixCraft is a one-person operation. I create all the content myself, with no help from AI or ML. I keep the content accurate and up-to-date.
  • Your privacy is my top priority. I don’t track you, show you ads, or spam you with emails. Just pure content in the true spirit of Linux and FLOSS.
  • Fast and clean browsing experience. nixCraft is designed to be fast and easy to use. You won’t have to deal with pop-ups, ads, cookie banners, or other distractions.
  • Support independent content creators. nixCraft is a labor of love, and it’s only possible thanks to the support of our readers. If you enjoy the content, please support us on Patreon or share this page on social media or your blog. Every bit helps.
Join Patreon

My failed attempt to set up VSCoce and Ansible Lightspeed on Ubuntu 20.04 LTS desktop

I quickly installed the following on my Ubuntu 20.04 LTS desktop:

  • Ansible
  • Ansible Lint
  • VSCode

While working with Ansible playbooks, I encountered errors because they required a minimum Ansible lint tool version of v5.0+. Additionally, Ansible Lightspeed has better functionality with Python v3.11, but unfortunately, both versions are unavailable on Ubuntu 20.04 LTS desktop. Further, when I failed to set it via pip3/pipx to grab the latest version of Ansible/Ansible-lint, and I met with more errors. At this stage, I’m having trouble connecting to the remote service using the VSCode Ansible Add-on, and as a result, I’m seeing an increase in errors and warnings. So, I knew I needed a separate dev environment to deal with these incompatibilities. After careful review, I found that this is how VSCode and Ansible Lightspeed works:

VSCode IDE
 |
 |
Your playbook (.YAML)
 |
 |
ansible-lint (it will only make call to Lightspeed if there are no warnings/errors)
 |
 |
Ansible Lightspeed Code Assistant Generative AI add-on 

Unfortunately, Red Hat does not support vim or Emacs in Ansible Lightspeed. They have chosen only to support VSCode at this time, but I hope this will change. Moving forward, I needed to set up VSCode, Chrome, Ansible-Lint 5.x+, Ansible, and Python 3.11.

Setting up VSCoce and Ansible Lightspeed on Ubuntu 22.04

I have chosen to install Ubuntu 22.04 LTS desktop with LXD to save headaches and keep my $HOME clean. Below are the commands to run a GUI application such as VSCode using Linux containers on Ubuntu 20.04 LTS:

Step 1 – Create the gui LXD profile

Type the following echo command:
$ echo "root:$UID:1" | sudo tee -a /etc/subuid /etc/subgid
Verify it using the cat command:
$ cat /etc/{subuid,subgid}

Step 2 – Set up GUI profile for LXD

Create an empty x11 profile for LXD:
$ lxc profile create x11
Next, make a new file named lxdx11.txt:

config:
  environment.DISPLAY: :0
  raw.idmap: both 1000 1000
  user.user-data: |
    #cloud-config
    runcmd:
      - 'sed -i "s/; enable-shm = yes/enable-shm = no/g" /etc/pulse/client.conf'
      - 'echo export PULSE_SERVER=unix:/tmp/.pulse-native | tee --append /home/ubuntu/.profile'
    packages:
      - x11-apps
      - mesa-utils
      - pulseaudio
description: GUI LXD profile
devices:
  PASocket:
    path: /tmp/.pulse-native
    source: /run/user/1000/pulse/native
    type: disk
  X0:
    path: /tmp/.X11-unix/X0
    source: /tmp/.X11-unix/X0
    type: disk
  mygpu:
    type: gpu
name: gui
used_by:

Run the following command
$ cat lxdx11.txt | lxc profile edit x11
$ lxc profile list

Step 3 – Launching X11/GUI container named ‘code-ansible’ using LXD

Run:
$ lxc launch ubuntu:22.04 code-ansible -p x11 -p default

Step 4 – Log into ‘code-ansible’

Type:
$ lxc exec code-ansible -- sudo --user ubuntu --login

Step 5 – Installing VSCode in Ubuntu Linux 22.04 LTS

Run:
ubuntu@code-ansible:~$ sudo snap install code --classic

Step 6 – Installing Google Chorme in Ubuntu Linux 22.04 LTS

I attempted to use Firefox and Chromium to authorize GitHub for the Red Hat Lightspeed service, but both browsers failed. This may be due to them being in the snap version. After spending 10 minutes trying to troubleshoot, I opted to try Chrome.
ubuntu@code-ansible:~$ sudo apt install xdg-utils
ubuntu@code-ansible:~$ cd /tmp/
ubuntu@code-ansible:~$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
ubuntu@code-ansible:~$ sudo dpkg -i google-chrome-stable_current_amd64.deb
ubuntu@code-ansible:~$ sudo apt-get -f install

Step 7 – Installing Ansible Linter and Ansible

Install Ansible, Linter and Python v3.11:
ubuntu@code-ansible:~$ sudo apt install ansible-lint ansible-mitogen ansible python3.11

Step 8 – Installing Ansible VScode extension

Start the VSCode IDE:
ubuntu@code-ansible:~$ code &
Search and install the Ansible extension. Once installed, configure the Ansible extension and enable Lightspeed service. I enabled both the “Ansible Lightspeed enabled” and “Enable Ansible Lightspeed with Watson Code Assistant inline suggestions” checkboxes in the settings. Finally, I clicked the Ansible “A” in the VS Code activity bar on the left-hand side to open the extension. Then, I clicked “Connect” and followed the prompts to log into GitHub using your credentials. This is where Chrome plays a role. It connects to GitHub and authorizes Ansible Lightspeed with Watson Code Assistant read-only access to my GitHub account. Once authorized, you need to read Red Hat terms and conditions. Accept it. Then, you get back to VSCode automatically using the xdg-open. This is how Red Hat connects and authorize it with its AI service for now.

Testing Ansible Lightspeed with IBM Watson Code Assistant is a generative AI service

Go ahead and create a new project directory and workspace in VSCode. I made a new Ansible playbook named test.yaml as follows. Ensure you set the correct path to Python 3.11, Ansible-lint, and file type to Ansible. Otherwise, it won’t work, and it won’t give any error. When everything is set correctly, you will see the status bar as follows, and that is the only way to know if you are connected to a generative AI service:

--- 
- name: Update all installed packages in the Debian Linux server using the apt module.

Click to enlarge

Generating an Ansible Lightspeed AI code suggestion

  1. Move to the end of the line where you defined the Ansible task. For example:
    - name: Update all installed packages in the Debian Linux server using the apt module.
  2. Press the [Enter] key.
  3. Watch Lightspeed in your IDE’s status bar. It will talk back to Red Hat/IBM service with animated sync ICON.
  4. Press TAB to accept the AI suggestion.
  5. That is all!

Conclusion

This is my first time installing VScode, and I wouldn’t say I like this IDE. It sucks, but AI-generating code is okay. It is not 100% accurate because it is learning from all over the web. It’s essential to exercise caution when using Ansible Lightspeed AI, as most Ansible playbooks run as root on the remote Linux or Unix fleet. As with any AI tool, it’s best to have prior knowledge of Ansible or any programming language to get the most out of it. However, this tool can be a helpful aid in writing playbooks and save you the time spent searching on Google or reading lengthy forums and blog posts. It’s not a replacement for an experienced Linux sysadmin, but it can certainly speed up the process. That is my first impression.

I would appreciate direct support for VIM or Emacs, and the exclusion of VSCode as a need to use RedHat’s AI service. I could have saved some time setting up a separate dev environment. On the other hand, having an independent dev environment is a good thingy for ease of management and security.

A word of caution

Before using this tool to write production code, reviewing the privacy policy and terms of service for Microsoft VSCoce and Red Hat/IBM is essential. Additionally, always follow your employer’s guidelines when using generative AI for coding, as some employers may prohibit using such tools. When using AI-driven chatbots or similar tools, avoid including confidential information, such as passwords, ssh-keys, API keys, or IP addresses in your playbook.

That’s all for now. I shared my recent experience, hoping it could be helpful for someone who uses Ubuntu Linux 22.04 LTS. My intention in writing this post was to offer some valuable tips and tricks. I will continue my exploration with this AI-based tool. Wishing you all happy coding!

References

Did you notice? 🧐

nixCraft is ad-free to protect your privacy and security. We rely on reader support to keep the site running. Please consider subscribing to us on Patreon or supporting us with a one-time support through PayPal or purchase official merchandise. Your support will help us cover the costs of hosting, CDN, DNS, and tutorial creation.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK