Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(anta.cli): Use configured anta inventory as output by default in get from-ansible #469

Merged
merged 10 commits into from
Nov 22, 2023

Conversation

titom73
Copy link
Collaborator

@titom73 titom73 commented Nov 16, 2023

Description

Use configured anta inventory if --output is not configured in anta get from-ansible command.

anta get from-ansible --ansible-inventory ../anta-lab/atd-inventory/inventory.yml
[19:02:09] INFO     Building inventory from ansible file ../anta-lab/atd-inventory/inventory.yml
[19:02:12] INFO     output anta inventory is: anta-lab/network-tests/inventory.yml
           INFO        * adding entry for cv_atd1
           INFO        * adding entry for spine1
           INFO        * adding entry for spine2
           INFO        * adding entry for leaf1 
           INFO        * adding entry for leaf2 
           INFO        * adding entry for leaf3
           INFO        * adding entry for leaf4
           INFO     ANTA device inventory file has been created in anta-lab/network-tests/inventory.yml

If destination file has content, then cli asks confirmation to user if he wants to overwrite:

anta get from-ansible --ansible-inventory ../anta-lab/atd-inventory/inventory.yml
[19:07:19] INFO     Building inventory from ansible file ../anta-lab/atd-inventory/inventory.yml
Your destination file (anta-lab/network-tests/inventory.yml) is not empty, continue? [y/n]: n
[19:07:27] CRITICAL conversion aborted since destination file is not empty 

If anta is executed in a non interactive environment, it breaks if destination file has content

To run script in a non-interactive environment, you can use --overwrite to tell anta it can overwrite file with content.

❯ anta get from-ansible --help
Usage: anta get from-ansible [OPTIONS]

  Build ANTA inventory from an ansible inventory YAML file

Options:
  -g, --ansible-group TEXT      Ansible group to filter
  -i, --ansible-inventory FILE  Path to your ansible inventory file to read
  -o, --output FILE             Path to save inventory file. If not
                                configured, use anta inventory file
  --overwrite                   Confirm script can overwrite existing
                                inventory file  [env var:
                                ANTA_GET_FROM_ANSIBLE_OVERWRITE]
  --help                        Show this message and exit.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have run pre-commit for code linting and typing (pre-commit run)
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (tox -e testenv)

@titom73
Copy link
Collaborator Author

titom73 commented Nov 17, 2023

Need to discuss about how to manage a change of the default inventory file
provided

This change is breaking CI in the second run

@titom73 titom73 added the Anta CLI All things around CLI label Nov 17, 2023
@titom73 titom73 marked this pull request as ready for review November 20, 2023 12:45
anta/cli/get/commands.py Show resolved Hide resolved
@titom73 titom73 requested a review from mtache November 21, 2023 17:13
@titom73 titom73 merged commit 63a4136 into aristanetworks:main Nov 22, 2023
19 checks passed
@titom73 titom73 mentioned this pull request Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Anta CLI All things around CLI rn: fix(anta.cli)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants