{"id":15050007,"url":"https://github.com/stephrobert/ansible-aisnippet","last_synced_at":"2025-04-10T02:13:33.941Z","repository":{"id":153319686,"uuid":"628892843","full_name":"stephrobert/ansible-aisnippet","owner":"stephrobert","description":"Generate ansible tasks with chatGPT","archived":false,"fork":false,"pushed_at":"2025-03-30T19:35:07.000Z","size":86,"stargazers_count":7,"open_issues_count":11,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T02:13:06.884Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stephrobert.png","metadata":{"files":{"readme":"README.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-04-17T07:44:02.000Z","updated_at":"2024-12-16T10:00:28.000Z","dependencies_parsed_at":"2024-07-21T09:46:34.258Z","dependency_job_id":"470254f0-dc13-4031-bd6d-184625792f8e","html_url":"https://github.com/stephrobert/ansible-aisnippet","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephrobert%2Fansible-aisnippet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephrobert%2Fansible-aisnippet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephrobert%2Fansible-aisnippet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephrobert%2Fansible-aisnippet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephrobert","download_url":"https://codeload.github.com/stephrobert/ansible-aisnippet/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248142902,"owners_count":21054671,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T21:24:13.092Z","updated_at":"2025-04-10T02:13:33.921Z","avatar_url":"https://github.com/stephrobert.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 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=\u003cyour token\u003e\n\nansible-aisnippet --help\n\n Usage: ansible-aisnippet [OPTIONS] COMMAND [ARGS]...\n\n╭─ Options ─────────────────────────────────────────────────────╮\n│ --version             -v        Show the application's        │\n│                                 version and exit.             │\n│ --install-completion            Install completion for the    │\n│                                 current shell.                │\n│ --show-completion               Show completion for the       │\n│                                 current shell, to copy it or  │\n│                                 customize the installation.   │\n│ --help                          Show this message and exit.   │\n╰───────────────────────────────────────────────────────────────╯\n╭─ Commands ────────────────────────────────────────────────────╮\n│ generate  Ask ChatGPT to write an ansible task using a        │\n│           template                                            │\n╰───────────────────────────────────────────────────────────────╯\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╭─ Arguments ──────────────────────────────────────────────────────────────────────╮\n│   text      [TEXT]  A description of task to get [default: Install package htop] │\n╰──────────────────────────────────────────────────────────────────────────────────╯\n╭─ Options ────────────────────────────────────────────────────────────────────────╮\n│ --verbose     -v            verbose mode                                         │\n│ --filetasks   -f      PATH  [default: None]                                      │\n│ --outputfile  -o      PATH  [default: None]                                      │\n│ --playbook    -p            Create a playbook                                    │\n│ --help                      Show this message and exit.                          │\n╰──────────────────────────────────────────────────────────────────────────────────╯\n```\n\n#### Generate a task\n\n```bash\nexport  OPENAI_KEY=\u003cyour token\u003e\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 \u0026\u0026 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=\u003cyour token\u003e\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephrobert%2Fansible-aisnippet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephrobert%2Fansible-aisnippet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephrobert%2Fansible-aisnippet/lists"}