Skip to content

Commit

Permalink
add support for roles removal
Browse files Browse the repository at this point in the history
  • Loading branch information
aine-etke committed Jul 15, 2024
1 parent 2f87f49 commit d6a2bd6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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?
Expand Down
28 changes: 25 additions & 3 deletions cmd/agru/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -13,6 +15,7 @@ var (
requirementsPath string
updateRequirementsFile bool
listInstalled bool
deleteInstalled string
installMissing bool
verbose bool
cleanup bool
Expand All @@ -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")
Expand All @@ -33,16 +37,34 @@ 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 {
installed := parser.GetInstalledRoles(rolesPath, parser.MergeFiles(entries, installOnly))
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 {
Expand Down

0 comments on commit d6a2bd6

Please sign in to comment.