diff --git a/README.md b/README.md index 77fa41c..d0a338b 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ * [What's the catch?](#whats-the-catch) * [only git repos are supported](#only-git-repos-are-supported) * [only roles are supported](#only-roles-are-supported) - * [only list/update/install operations are supported](#only-listupdateinstall-operations-are-supported) + * [only list/update/install/remove operations are supported](#only-listupdateinstallremove-operations-are-supported) * [Where to get?](#where-to-get) * [Binaries and distro-specific packages](#binaries-and-distro-specific-packages) * [Build yourself](#build-yourself) @@ -34,9 +34,11 @@ Because `ansible-galaxy` is slow, **very** slow. And irrational. And miss some f ## How? -``` +```bash Usage of agru: -c cleanup temporary files (default true) + -d string + delete installed role, all other flags are ignored -i install missing roles (default true) -l list installed roles -p string @@ -47,6 +49,30 @@ Usage of agru: -v verbose output ``` +**list installed roles** + +```bash +$ agru -l +``` + +**install role from the requirements file** + +```bash +$ agru +``` + +**update requirements file if newer versions are available** + +```bash +$ agru -u +``` + +**remove already installed role** + +```bash +$ agru -d traefik +``` + ## What's the catch? Do you think A.G.R.U. is too good to be true? Well, it's true, but it has limitations: @@ -71,10 +97,9 @@ does **not** work: No collections at this moment, at all. -### only list/update/install operations are supported +### only list/update/install/remove operations are supported -No role upload to galaxy, no role removal from galaxy. -In fact, galaxy API is not used at all, thus no API-related actions are supported +Ansible Galaxy API is not used at all, thus no API-related actions are supported ## Where to get? diff --git a/cmd/agru/main.go b/cmd/agru/main.go index 7c64953..7ebbe5f 100644 --- a/cmd/agru/main.go +++ b/cmd/agru/main.go @@ -3,6 +3,8 @@ package main import ( "flag" "fmt" + "os" + "path" "gitlab.com/etke.cc/int/agru/internal/parser" "gitlab.com/etke.cc/int/agru/internal/utils" @@ -13,6 +15,7 @@ var ( requirementsPath string updateRequirementsFile bool listInstalled bool + deleteInstalled string installMissing bool verbose bool cleanup bool @@ -21,6 +24,7 @@ var ( func main() { flag.StringVar(&requirementsPath, "r", "requirements.yml", "ansible-galaxy requirements file") flag.StringVar(&rolesPath, "p", "roles/galaxy/", "path to install roles") + flag.StringVar(&deleteInstalled, "d", "", "delete installed role, all other flags are ignored") flag.BoolVar(&listInstalled, "l", false, "list installed roles") flag.BoolVar(&installMissing, "i", true, "install missing roles") flag.BoolVar(&updateRequirementsFile, "u", false, "update requirements file if newer versions are available") @@ -33,9 +37,21 @@ func main() { utils.Log(fmt.Sprintf("\033[1ma\033[0mnsible-\033[1mg\033[0malaxy \033[1mr\033[0mequirements.yml \033[1mu\033[0mpdater (list=%t update=%t cleanup=%t verbose=%t)", listInstalled, updateRequirementsFile, cleanup, verbose)) utils.Log("parsing", requirementsPath) entries, installOnly := parser.ParseFile(requirementsPath) - if updateRequirementsFile { - utils.Log("updating", requirementsPath) - parser.UpdateFile(entries, requirementsPath) + + if deleteInstalled != "" { + installed := parser.GetInstalledRoles(rolesPath, parser.MergeFiles(entries, installOnly)) + for _, entry := range installed { + if entry.GetName() == deleteInstalled { + utils.Log("deleting", entry.GetName()) + if err := os.RemoveAll(path.Join(rolesPath, entry.GetName())); err != nil { + utils.Log("ERROR: cannot delete role:", err) + } + utils.Log("done") + return + } + } + utils.Log("role", deleteInstalled, "not found") + return } if listInstalled { @@ -43,6 +59,12 @@ func main() { for _, entry := range installed { fmt.Println("-", entry.GetName()+",", entry.GetInstallInfo(rolesPath).Version) } + return + } + + if updateRequirementsFile { + utils.Log("updating", requirementsPath) + parser.UpdateFile(entries, requirementsPath) } if installMissing {