Skip to main content

ansible-aisnippet

Features

Quickstart

Install python package

Install the latest version ansible-aisnippet with pip or pipx

pip install ansible-aisnippet

Usage

You must have an openai.api_key. You can create it from openai website.

export  OPENAI_KEY=<your token>

ansible-aisnippet --help

 Usage: ansible-aisnippet [OPTIONS] COMMAND [ARGS]...

╭─ Options ─────────────────────────────────────────────────────╮
│ --version             -v        Show the application's        │
│                                 version and exit.             │
│ --install-completion            Install completion for the    │
│                                 current shell.                │
│ --show-completion               Show completion for the       │
│                                 current shell, to copy it or  │
│                                 customize the installation.   │
│ --help                          Show this message and exit.   │
╰───────────────────────────────────────────────────────────────╯
╭─ Commands ────────────────────────────────────────────────────╮
│ generate  Ask ChatGPT to write an ansible task using a        │
│           template                                            │
╰───────────────────────────────────────────────────────────────╯

Generate task(s)

ansible-aisnippet can generate an or several ansible task from a description or a filetasks.

ansible-aisnippet generate --help

 Usage: ansible-aisnippet generate [OPTIONS] [TEXT]

 Ask ChatGPT to write an ansible task using a template

╭─ Arguments ──────────────────────────────────────────────────────────────────────╮
│   text      [TEXT]  A description of task to get [default: Install package htop] │
╰──────────────────────────────────────────────────────────────────────────────────╯
╭─ Options ────────────────────────────────────────────────────────────────────────╮
│ --verbose     -v            verbose mode                                         │
│ --filetasks   -f      PATH  [default: None]                                      │
│ --outputfile  -o      PATH  [default: None]                                      │
│ --playbook    -p            Create a playbook                                    │
│ --help                      Show this message and exit.                          │
╰──────────────────────────────────────────────────────────────────────────────────╯

Generate a task

export  OPENAI_KEY=<your token>

ansible-aisnippet generate "execute command to start /opt/application/start.sh create /var/run/test.lock"
Building prefix dict from the default dictionary ...
Loading model from cache /tmp/jieba.cache
Loading model cost 0.686 seconds.
Prefix dict has been built successfully.
name: Execute command to start /opt/application/start.sh create /var/run/test.lock

ansible.builtin.command:
  chdir: /opt/application
  cmd: ./start.sh && touch /var/run/test.lock
  creates: /var/run/test.lock
  removes: ''

Generate severals tasks

ansible-aisnippet can generate severals tasks from a file. The file is a yaml file which contains a list of tasks and blocks

Ex:

- task: Install package htop, nginx and net-tools with generic module
- task: Copy file from local file /tmp/toto to remote /tmp/titi set mode 0666 owner bob group www
  register: test
- name: A block
  when: test.rc == 0
  block:
    - task: wait for port 6300 on localhost timeout 25
  rescue:
    - task: Execute command /opt/application/start.sh creates /var/run/test.lock
- task: Download file from https://tmp.io/test/ set mode 0640 and force true

This file produces this result :

export  OPENAI_KEY=<your token>

ansible-aisnippet generate -f test.yml -p
Building prefix dict from the default dictionary ...
Loading model from cache /tmp/jieba.cache
Loading model cost 0.671 seconds.
Prefix dict has been built successfully.
Result:

- name: Playbook generated with chatgpt
  hosts: all
  gather_facts: true
  tasks:
  - name: Install package htop, nginx and net-tools
    ansible.builtin.yum:
      name:
      - htop
      - nginx
      - net-tools
      state: present
  - name: Copy file from local file /tmp/toto to remote /tmp/titi
    ansible.builtin.copy:
      src: /tmp/toto
      dest: /tmp/titi
      mode: '0666'
      owner: bob
      group: www
    register: test
  - name: A block
    when: test.rc == 0
    block:
    - name: Wait for port 6300 on localhost timeout 25
      ansible.builtin.wait_for:
        host: 127.0.0.1
        port: '6300'
        timeout: '25'
    rescue:
    - name: Execute command /opt/application/start.sh creates /var/run/test.lock
      ansible.builtin.command:
        chdir: /tmp/test
        cmd: /opt/application/start.sh
        creates: /var/run/test.lock
  - name: Download file from https://tmp.io/test/
    ansible.builtin.get_url:
      backup: false
      decompress: true
      dest: /tmp/test
      force: true
      group: root
      mode: '0640'
      owner: root
      timeout: '10'
      tmp_dest: /tmp/test
      url: https://tmp.io/test/
      validate_certs: true

Metadata

Release files for ansible-aisnippet 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ansible-aisnippet 0.1.2
File Size Uploaded Provenance
ansible_aisnippet-0.1.2.tar.gz 17.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ansible-aisnippet 0.1.2
File Interpreter ABI Platform
ansible_aisnippet-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 38.7 kB

Release files / ansible_aisnippet-0.1.2.tar.gz

Download URL ansible_aisnippet-0.1.2.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ffb24a7c187670d8b487b17190190ef63c15f9df2c8e340becb40935d07c1a65
BLAKE2b-256 checksum
How to use checksums
e6dd61a19647883e03bcc2687df7d0bcb02f92fbc13f81fb323eb1f36a75ce16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.3 Linux/5.15.0-1035-azure

Release files / ansible_aisnippet-0.1.2-py3-none-any.whl

Download URL ansible_aisnippet-0.1.2-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4a7f1b036b002eca9f89067a3ca92473afe77a47cf8f61caf350d676a32fb860
BLAKE2b-256 checksum
How to use checksums
f216f0cb2d84aadb5a4c8ad4dcae891f063c3d1d57ec80785351f2489ff31a93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.11.3 Linux/5.15.0-1035-azure

Security for ansible-aisnippet 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page