add option to list already installed roles

This commit is contained in:
Aine 2024-07-15 14:04:17 +03:00
parent 3ef2fcbfb9
commit 2f87f4919d
No known key found for this signature in database
GPG key ID: 34969C908CCA2804
4 changed files with 37 additions and 6 deletions

View file

@ -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 update/install operations are supported](#only-updateinstall-operations-are-supported)
* [only list/update/install operations are supported](#only-listupdateinstall-operations-are-supported)
* [Where to get?](#where-to-get)
* [Binaries and distro-specific packages](#binaries-and-distro-specific-packages)
* [Build yourself](#build-yourself)
@ -37,6 +37,8 @@ Because `ansible-galaxy` is slow, **very** slow. And irrational. And miss some f
```
Usage of agru:
-c cleanup temporary files (default true)
-i install missing roles (default true)
-l list installed roles
-p string
path to install roles (default "roles/galaxy/")
-r string
@ -69,9 +71,9 @@ does **not** work:
No collections at this moment, at all.
### only update/install operations are supported
### only list/update/install operations are supported
No list, no role upload to galaxy, no role removal from galaxy.
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
## Where to get?

View file

@ -12,6 +12,8 @@ var (
rolesPath string
requirementsPath string
updateRequirementsFile bool
listInstalled bool
installMissing bool
verbose bool
cleanup bool
)
@ -19,6 +21,8 @@ var (
func main() {
flag.StringVar(&requirementsPath, "r", "requirements.yml", "ansible-galaxy requirements file")
flag.StringVar(&rolesPath, "p", "roles/galaxy/", "path to install roles")
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")
flag.BoolVar(&cleanup, "c", true, "cleanup temporary files")
flag.BoolVar(&verbose, "v", false, "verbose output")
@ -26,7 +30,7 @@ func main() {
utils.Verbose = verbose
utils.Log(fmt.Sprintf("\033[1ma\033[0mnsible-\033[1mg\033[0malaxy \033[1mr\033[0mequirements.yml \033[1mu\033[0mpdater (update=%t cleanup=%t verbose=%t)", updateRequirementsFile, cleanup, verbose))
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 {
@ -34,8 +38,17 @@ func main() {
parser.UpdateFile(entries, requirementsPath)
}
utils.Log("installing/updating roles (if any)")
parser.InstallMissingRoles(rolesPath, parser.MergeFiles(entries, installOnly), cleanup)
if listInstalled {
installed := parser.GetInstalledRoles(rolesPath, parser.MergeFiles(entries, installOnly))
for _, entry := range installed {
fmt.Println("-", entry.GetName()+",", entry.GetInstallInfo(rolesPath).Version)
}
}
if installMissing {
utils.Log("installing/updating roles (if any)")
parser.InstallMissingRoles(rolesPath, parser.MergeFiles(entries, installOnly), cleanup)
}
utils.Log("done")
}

View file

@ -37,6 +37,18 @@ func InstallMissingRoles(rolesPath string, entries models.File, cleanup bool) {
wg.Wait()
}
// GetInstalledRoles returns all roles that are already installed
func GetInstalledRoles(rolesPath string, entries models.File) models.File {
installed := models.File{}
for _, entry := range entries {
entry := entry
if entry.GetInstallInfo(rolesPath).Version != "" {
installed = append(installed, entry)
}
}
return installed
}
// getNewVersion checks for newer git tag available on the src's remote
func getNewVersion(src, version string) string {
if ignoredVersions[version] {

View file

@ -8,6 +8,10 @@ update *flags:
go mod tidy
go mod vendor
# install app
install:
go install ./cmd/agru
# run linter
lint:
golangci-lint run ./...