Skip to content

Commit

Permalink
Merge branch 'main' of github.com:ansible/vscode-ansible into chore/u…
Browse files Browse the repository at this point in the history
…pdate_helper
  • Loading branch information
audgirka committed Oct 22, 2024
2 parents 7b83edb + 1f695b2 commit cfc80c5
Show file tree
Hide file tree
Showing 26 changed files with 360 additions and 127 deletions.
2 changes: 2 additions & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ bitness
bthornto
cacheable
cfgs
charliermarsh
checode
chromedriver
chronographer
Expand Down Expand Up @@ -104,6 +105,7 @@ esbenp
extest
extester
fgierlinger
fileicon
fqcn
fredericgiquel
ganeshrn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
# https://github.com/marketplace/actions/setup-wsl
- name: Activate WSL
if: contains(matrix.shell, 'wsl')
uses: Vampire/setup-wsl@v3.1.1
uses: Vampire/setup-wsl@v3.1.3
with:
distribution: Ubuntu-22.04
set-as-default: "true"
Expand Down
16 changes: 15 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ exclude: >
minimum_pre_commit_version: 2.9.0 # types_or
repos:
- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.14.0
rev: v8.15.2
hooks:
- id: cspell
# name: Spell check with cspell
Expand All @@ -41,6 +41,20 @@ repos:
- --color=always
- -e
- SC1091
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
types_or: [python, pyi]
- id: ruff-format # must be after ruff
types_or: [python, pyi]
- repo: https://github.com/psf/black # must be after ruff
rev: 24.10.0
hooks:
- id: black
- repo: local
hooks:
- id: depcheck
Expand Down
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"recommendations": [
"DavidAnson.vscode-markdownlint",
"charliermarsh.ruff",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"hbenl.vscode-mocha-test-adapter",
Expand Down
9 changes: 8 additions & 1 deletion .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
!LICENSE
!docs/README.md
!images/ansible.svg
!images/ansible-fileicon.svg
!images/logo.png
!jinja-language-configuration.json
!media/style.css
Expand Down Expand Up @@ -61,4 +62,10 @@
!media/walkthroughs/discoverAdt/test-ansible-lint.gif
!media/walkthroughs/discoverAdt/test-molecule.gif
!media/walkthroughs/discoverAdt/test-pytest-ansible.png
!media/walkthroughs/discoverAdt/test-tox-ansible.gif
!media/walkthroughs/startAutomatingPlaybook/create-lightspeed-completion.gif
!media/walkthroughs/startAutomatingPlaybook/create-lightspeed-playbook.gif
!media/walkthroughs/startAutomatingPlaybook/create-playbook.png
!media/walkthroughs/startAutomatingPlaybook/enable-lightspeed.md
!media/walkthroughs/startAutomatingPlaybook/learning.png
!media/walkthroughs/startAutomatingPlaybook/open-folder.png
!media/walkthroughs/startAutomatingPlaybook/playbook-project.md
38 changes: 18 additions & 20 deletions examples/dynamic_inventory.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python

'''
"""
Example custom dynamic inventory script for Ansible, in Python.
'''
"""

import argparse
from time import sleep
Expand All @@ -12,6 +12,7 @@
except ImportError:
import simplejson as json


class ExampleInventory(object):

def __init__(self):
Expand All @@ -29,40 +30,37 @@ def __init__(self):
else:
self.inventory = self.empty_inventory()

print (json.dumps(self.inventory));
print(json.dumps(self.inventory))

# Example inventory for testing.
def example_inventory(self):
sleep(1)
return {
'python_hosts': {
'hosts': ['10.220.21.24', '10.220.21.27'],
'vars': {
'ansible_ssh_user': 'projectuser',
}
"python_hosts": {
"hosts": ["10.220.21.24", "10.220.21.27"],
"vars": {
"ansible_ssh_user": "projectuser",
},
},
'_meta': {
'hostvars': {
'10.220.21.24': {
'host_specific_var': 'testhost'
},
'10.220.21.27': {
'host_specific_var': 'towerhost'
}
"_meta": {
"hostvars": {
"10.220.21.24": {"host_specific_var": "testhost"},
"10.220.21.27": {"host_specific_var": "towerhost"},
}
}
},
}

# Empty inventory for testing.
def empty_inventory(self):
return {'_meta': {'hostvars': {}}}
return {"_meta": {"hostvars": {}}}

# Read the command line args passed to the script.
def read_cli_args(self):
parser = argparse.ArgumentParser()
parser.add_argument('--list', action = 'store_true')
parser.add_argument('--host', action = 'store')
parser.add_argument("--list", action="store_true")
parser.add_argument("--host", action="store")
self.args = parser.parse_args()


# Get the inventory.
ExampleInventory()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions media/walkthroughs/startAutomatingPlaybook/enable-lightspeed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- markdownlint-disable MD033 MD041 MD013-->
<figure align="center">
<img src="create-lightspeed-completion.gif" alt="image missing" />
<figcaption>Ansible Lightspeed's in-code functionality</figcaption>
</figure>
<br>
<figure align="center">
<img src="create-lightspeed-playbook.gif" alt="image missing" />
<figcaption>Generate playbooks with Ansible Lightspeed inside the Ansible extension</figcaption>
</figure>
<br>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- markdownlint-disable MD033 MD041 MD013-->
<figure align="center">
<img src="open-folder.png" alt="image missing" />
</figure>
<br>
57 changes: 57 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,55 @@
}
]
},
{
"id": "start-automating-playbook",
"title": "Start automating with your first Ansible playbook",
"description": "Create your first automation playbook while learning best practices.",
"steps": [
{
"id": "enable-lightspeed-playbook",
"title": "Enable Ansible Lightspeed",
"description": "Use generative AI to assist in your automation content creation.\nAnsible Lightspeed is available to Ansible Automation Platform users.\nCheck availability by logging in with your Red Hat account.\n[Log in with Red Hat ↗](command:ansible.lightspeed.signInWithLightspeed)\n[Learn more ↗](https://www.redhat.com/en/technologies/management/ansible/ansible-lightspeed) ",
"media": {
"markdown": "media/walkthroughs/startAutomatingPlaybook/enable-lightspeed.md"
}
},
{
"id": "create-project-playbook",
"title": "Create an Ansible playbook project",
"description": "Create a pre-configured Ansible playbook project repository.\n[Create an Ansible playbook project](command:ansible.content-creator.create-ansible-project)",
"media": {
"markdown": "media/walkthroughs/startAutomatingPlaybook/playbook-project.md"
}
},
{
"id": "create-ansible-playbook",
"title": "Create an Ansible playbook",
"description": "Ansible Playbooks are lists of tasks that automatically execute for your specified inventory or groups of hosts.\nWithin your playbook project, create a new Ansible Playbook.\nIf Ansible Lightspeed is enabled in settings, a generation template will appear. Otherwise, this creates an empty playbook for you to modify.\n[Create Ansible playbook](command:ansible.create-playbook-options)",
"media": {
"image": "media/walkthroughs/startAutomatingPlaybook/create-playbook.png",
"altText": "No image found"
}
},
{
"id": "save-ansible-playbook",
"title": "Save your playbook to a playbook project",
"description": "Save your playbook in your new playbook project.\nWe recommend saving your playbooks under the **playbooks/** folder inside your project.",
"media": {
"markdown": "media/walkthroughs/startAutomatingPlaybook/playbook-project.md"
}
},
{
"id": "learn-more-playbook",
"title": "Learn more about playbooks",
"description": "If you want to become a master, start digging into our Ansible playbook learning resources.\n[Check out learning resources ↗](https://www.redhat.com/en/topics/automation/what-is-an-ansible-playbook)",
"media": {
"image": "media/walkthroughs/startAutomatingPlaybook/learning.png",
"altText": "No image found"
}
}
]
},
{
"id": "discover-ansible-development-tools",
"title": "Discover Ansible Development Tools",
Expand Down Expand Up @@ -283,6 +332,14 @@
"command": "ansible.python-settings.open",
"title": "Ansible: Open Python Settings"
},
{
"command": "ansible.create-empty-playbook",
"title": "Ansible: Create an empty Ansible playbook"
},
{
"command": "ansible.create-playbook-options",
"title": "Ansible: Create an empty playbook or with Lightspeed (if enabled)"
},
{
"command": "ansible.content-creator.menu",
"title": "Open Ansible Development Tools menu"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#!/usr/bin/env python3

'''
"""
Example custom dynamic inventory script for Ansible, in Python.
'''
"""

import argparse
from time import sleep

try:
import json
except ImportError:
import simplejson as json

class ExampleInventory(object):

class ExampleInventory(object):
def __init__(self):
self.inventory = {}
self.read_cli_args()
Expand All @@ -29,41 +28,38 @@ def __init__(self):
else:
self.inventory = self.empty_inventory()

print(json.dumps(self.inventory));
print(json.dumps(self.inventory))

# Example inventory for testing.
def example_inventory(self):
# sleep is added to create an impression of a complex dynamic inventory file that takes time to fetch hosts
# sleep(1)
return {
'python_hosts': {
'hosts': ['10.220.21.24', '10.220.21.27'],
'vars': {
'ansible_ssh_user': 'projectuser',
}
"python_hosts": {
"hosts": ["10.220.21.24", "10.220.21.27"],
"vars": {
"ansible_ssh_user": "projectuser",
},
},
'_meta': {
'hostvars': {
'10.220.21.24': {
'host_specific_var': 'testhost'
},
'10.220.21.27': {
'host_specific_var': 'towerhost'
}
"_meta": {
"hostvars": {
"10.220.21.24": {"host_specific_var": "testhost"},
"10.220.21.27": {"host_specific_var": "towerhost"},
}
}
},
}

# Empty inventory for testing.
def empty_inventory(self):
return {'_meta': {'hostvars': {}}}
return {"_meta": {"hostvars": {}}}

# Read the command line args passed to the script.
def read_cli_args(self):
parser = argparse.ArgumentParser()
parser.add_argument('--list', action = 'store_true')
parser.add_argument('--host', action = 'store')
parser.add_argument("--list", action="store_true")
parser.add_argument("--host", action="store")
self.args = parser.parse_args()


# Get the inventory.
ExampleInventory()
4 changes: 1 addition & 3 deletions packages/ansible-language-server/tools/version_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def sync_als_version_in_vscode_ansible_devel():
with open("../vscode-ansible/package.json") as fp:
package_json_vscode_ansible = json.load(fp)

package_json_vscode_ansible["dependencies"][
"@ansible/ansible-language-server"
] = version_als
package_json_vscode_ansible["dependencies"]["@ansible/ansible-language-server"] = version_als
with open("../vscode-ansible/package.json", "w") as fp:
json.dump(package_json_vscode_ansible, fp, indent=4)

Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[tool.black]
enable-unstable-feature = ["string_processing"]
line-length = 100
preview = true

[tool.codespell]
builtin = "clear,rare,code"
check-filenames = true
Expand All @@ -24,3 +29,9 @@ norecursedirs = [
"out",
"node_modules",
]

[tool.ruff]
exclude = ["examples"]
fix = true
line-length = 100
target-version = "py310"
2 changes: 1 addition & 1 deletion src/definitions/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ export const IncludeVarValidTaskName = [

export const ANSIBLE_LIGHTSPEED_API_TIMEOUT = 50000;

export const ANSIBLE_CREATOR_VERSION_MIN = "24.10.0";
export const ANSIBLE_CREATOR_VERSION_MIN = "24.10.1";
29 changes: 29 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,36 @@ export async function activate(context: ExtensionContext): Promise<void> {
},
),
);
context.subscriptions.push(
vscode.commands.registerCommand(
"ansible.create-playbook-options",
async () => {
if (
await workspace.getConfiguration("ansible").get("lightspeed.enabled")
) {
vscode.commands.executeCommand(
"ansible.lightspeed.playbookGeneration",
);
} else {
vscode.commands.executeCommand("ansible.create-empty-playbook");
}
},
),
);
context.subscriptions.push(
vscode.commands.registerCommand("ansible.create-empty-playbook", () => {
const playbookTemplate = `---\n# Write your playbook below.\n# Replace these contents with the tasks you'd like to complete and the modules you need.\n# For help getting started, check out https://www.redhat.com/en/topics/automation/what-is-an-ansible-playbook\n`;

vscode.workspace
.openTextDocument({
content: playbookTemplate,
language: "ansible",
})
.then((newDocument) => {
vscode.window.showTextDocument(newDocument);
});
}),
);
// open ansible language server logs
context.subscriptions.push(
vscode.commands.registerCommand("ansible.open-language-server-logs", () => {
Expand Down
Loading

0 comments on commit cfc80c5

Please sign in to comment.