# ansible-aisnippet
## Features
## Quickstart
### Install python package
Install the latest version `ansible-aisnippet` with `pip` or `pipx`
```bash
pip install ansible-aisnippet
```
### Usage
You must have an openai.api_key. You can create it from [openai](https://platform.openai.com/account/api-keys) website.
```bash
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.
```bash
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
```bash
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:
```yaml
- 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 :
```bash
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
```
Raw data
{
"_id": null,
"home_page": "https://blog.stephane-robert.info/",
"name": "ansible-aisnippet",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10,<4.0",
"maintainer_email": "",
"keywords": "ansible,module,ChatGPT",
"author": "Stephane ROBERT",
"author_email": "robert.stephane.28@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e6/dd/61a19647883e03bcc2687df7d0bcb02f92fbc13f81fb323eb1f36a75ce16/ansible_aisnippet-0.1.2.tar.gz",
"platform": null,
"description": "# ansible-aisnippet\n\n## Features\n\n## Quickstart\n\n### Install python package\n\nInstall the latest version `ansible-aisnippet` with `pip` or `pipx`\n\n```bash\npip install ansible-aisnippet\n```\n\n### Usage\n\nYou must have an openai.api_key. You can create it from [openai](https://platform.openai.com/account/api-keys) website.\n\n```bash\nexport OPENAI_KEY=<your token>\n\nansible-aisnippet --help\n\n Usage: ansible-aisnippet [OPTIONS] COMMAND [ARGS]...\n\n\u256d\u2500 Options \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n\u2502 --version -v Show the application's \u2502\n\u2502 version and exit. \u2502\n\u2502 --install-completion Install completion for the \u2502\n\u2502 current shell. \u2502\n\u2502 --show-completion Show completion for the \u2502\n\u2502 current shell, to copy it or \u2502\n\u2502 customize the installation. \u2502\n\u2502 --help Show this message and exit. \u2502\n\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n\u256d\u2500 Commands \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n\u2502 generate Ask ChatGPT to write an ansible task using a \u2502\n\u2502 template \u2502\n\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n```\n\n### Generate task(s)\n\nansible-aisnippet can generate an or several ansible task from a description or\na filetasks.\n\n```bash\nansible-aisnippet generate --help\n\n Usage: ansible-aisnippet generate [OPTIONS] [TEXT]\n\n Ask ChatGPT to write an ansible task using a template\n\n\u256d\u2500 Arguments \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n\u2502 text [TEXT] A description of task to get [default: Install package htop] \u2502\n\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n\u256d\u2500 Options \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256e\n\u2502 --verbose -v verbose mode \u2502\n\u2502 --filetasks -f PATH [default: None] \u2502\n\u2502 --outputfile -o PATH [default: None] \u2502\n\u2502 --playbook -p Create a playbook \u2502\n\u2502 --help Show this message and exit. \u2502\n\u2570\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u256f\n```\n\n#### Generate a task\n\n```bash\nexport OPENAI_KEY=<your token>\n\nansible-aisnippet generate \"execute command to start /opt/application/start.sh create /var/run/test.lock\"\nBuilding prefix dict from the default dictionary ...\nLoading model from cache /tmp/jieba.cache\nLoading model cost 0.686 seconds.\nPrefix dict has been built successfully.\nname: Execute command to start /opt/application/start.sh create /var/run/test.lock\n\nansible.builtin.command:\n chdir: /opt/application\n cmd: ./start.sh && touch /var/run/test.lock\n creates: /var/run/test.lock\n removes: ''\n```\n\n#### Generate severals tasks\n\nansible-aisnippet can generate severals tasks from a file. The file is a yaml file which contains a list of tasks and blocks\n\nEx:\n\n```yaml\n- task: Install package htop, nginx and net-tools with generic module\n- task: Copy file from local file /tmp/toto to remote /tmp/titi set mode 0666 owner bob group www\n register: test\n- name: A block\n when: test.rc == 0\n block:\n - task: wait for port 6300 on localhost timeout 25\n rescue:\n - task: Execute command /opt/application/start.sh creates /var/run/test.lock\n- task: Download file from https://tmp.io/test/ set mode 0640 and force true\n```\n\nThis file produces this result :\n\n```bash\nexport OPENAI_KEY=<your token>\n\nansible-aisnippet generate -f test.yml -p\nBuilding prefix dict from the default dictionary ...\nLoading model from cache /tmp/jieba.cache\nLoading model cost 0.671 seconds.\nPrefix dict has been built successfully.\nResult:\n\n- name: Playbook generated with chatgpt\n hosts: all\n gather_facts: true\n tasks:\n - name: Install package htop, nginx and net-tools\n ansible.builtin.yum:\n name:\n - htop\n - nginx\n - net-tools\n state: present\n - name: Copy file from local file /tmp/toto to remote /tmp/titi\n ansible.builtin.copy:\n src: /tmp/toto\n dest: /tmp/titi\n mode: '0666'\n owner: bob\n group: www\n register: test\n - name: A block\n when: test.rc == 0\n block:\n - name: Wait for port 6300 on localhost timeout 25\n ansible.builtin.wait_for:\n host: 127.0.0.1\n port: '6300'\n timeout: '25'\n rescue:\n - name: Execute command /opt/application/start.sh creates /var/run/test.lock\n ansible.builtin.command:\n chdir: /tmp/test\n cmd: /opt/application/start.sh\n creates: /var/run/test.lock\n - name: Download file from https://tmp.io/test/\n ansible.builtin.get_url:\n backup: false\n decompress: true\n dest: /tmp/test\n force: true\n group: root\n mode: '0640'\n owner: root\n timeout: '10'\n tmp_dest: /tmp/test\n url: https://tmp.io/test/\n validate_certs: true\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "Ansible-aisnippet Generate ansible tasks with ChatGPT.",
"version": "0.1.2",
"split_keywords": [
"ansible",
"module",
"chatgpt"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f216f0cb2d84aadb5a4c8ad4dcae891f063c3d1d57ec80785351f2489ff31a93",
"md5": "5ea07f5cb10a78a24e1f2720f036cbba",
"sha256": "4a7f1b036b002eca9f89067a3ca92473afe77a47cf8f61caf350d676a32fb860"
},
"downloads": -1,
"filename": "ansible_aisnippet-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "5ea07f5cb10a78a24e1f2720f036cbba",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10,<4.0",
"size": 21578,
"upload_time": "2023-04-17T09:05:32",
"upload_time_iso_8601": "2023-04-17T09:05:32.723278Z",
"url": "https://files.pythonhosted.org/packages/f2/16/f0cb2d84aadb5a4c8ad4dcae891f063c3d1d57ec80785351f2489ff31a93/ansible_aisnippet-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e6dd61a19647883e03bcc2687df7d0bcb02f92fbc13f81fb323eb1f36a75ce16",
"md5": "117a9775d2cd62f865f7682d26a942e6",
"sha256": "ffb24a7c187670d8b487b17190190ef63c15f9df2c8e340becb40935d07c1a65"
},
"downloads": -1,
"filename": "ansible_aisnippet-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "117a9775d2cd62f865f7682d26a942e6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10,<4.0",
"size": 17131,
"upload_time": "2023-04-17T09:05:34",
"upload_time_iso_8601": "2023-04-17T09:05:34.117067Z",
"url": "https://files.pythonhosted.org/packages/e6/dd/61a19647883e03bcc2687df7d0bcb02f92fbc13f81fb323eb1f36a75ce16/ansible_aisnippet-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-17 09:05:34",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "ansible-aisnippet"
}