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

provisioner: merge galaxy config into common #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nywilken
Copy link
Member

@nywilken nywilken commented Apr 27, 2021

The Ansible galaxy arguments for both provisioners were duplicated among the provisioners although they are essentially the same.
Since they're the same, we move the common code and arguments into a common package so it can be reused between both provisioners.

@nywilken nywilken requested a review from a team as a code owner April 27, 2021 14:52
@nywilken
Copy link
Member Author

@SwampDragons this is where I got to on the refactor. Sharing in case you find anything usable.

@SwampDragons
Copy link
Contributor

Thanks. I'll take a look at it when I have some downtime.

@hashicorp-cla
Copy link

hashicorp-cla commented Mar 12, 2022

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nits/typos/questions, other than that LGTM, that's a good improvement

provisioner/ansible/provisioner.go Show resolved Hide resolved
provisioner/common/common.go Outdated Show resolved Hide resolved
provisioner/common/common.go Show resolved Hide resolved
@nywilken nywilken force-pushed the feature/ansible-collection-support branch from c477912 to d9ed1db Compare June 10, 2022 18:33
Base automatically changed from feature/ansible-collection-support to main June 10, 2022 18:51
@lbajolet-hashicorp lbajolet-hashicorp force-pushed the feature/ansible-collection-support-refactor branch 3 times, most recently from e018859 to b7223d3 Compare October 24, 2023 14:48
The Ansible galaxy arguments for both provisioners were duplicated among
the provisioners although they are essentially the same.
Since they're the same, we move the common code and arguments into a
common package so it can be reused between both provisioners.
@lbajolet-hashicorp lbajolet-hashicorp force-pushed the feature/ansible-collection-support-refactor branch from b7223d3 to 3fa204b Compare October 24, 2023 15:01
@lbajolet-hashicorp lbajolet-hashicorp changed the title initial consolidation of executeGalaxy configuration provisioner: merge galaxy config into common Oct 24, 2023
Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ready for a review @nywilken

Copy link
Member Author

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for re-rolling this change. Overall it looks good. I left a suggestion on the BuildGalaxyArgs function to always return something.

Comment on lines +68 to +78
// If roles keyword present (v2 format), or no collections keyword present (v1), install roles
if hasRoles || !hasCollections {
return roleArgs, nil
}

// If collections keyword present (v2 format), install collections
if hasCollections {
return collectionArgs, nil
}

return nil, nil
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return nil,nil feels like there is an error case we are missing. As it stands if we do return nil args with no error the execution of the args returned from BuildGalaxyArgs would fail. Would it be more appropriate to always return roleArgs or maybe an error if have no roles since the Galaxy file is invalid?

	// If collections keyword present (v2 format), install collections 
	if hasCollections {
		return collectionArgs, nil
	}
	
	// If roles keyword present (v2 format), or no collections keyword present (v1), install roles
	if hasRoles  {
		return roleArgs, nil
	}

	return nil, fmt.Errorf("messaging about the requirements file not containing any roles or collections")

Alternatively you can just return the roleArgs and let Ansible handle the errors

	// If collections keyword present (v2 format), install collections 
	if hasCollections {
		return collectionArgs, nil
	}

	return roleArgs, nil
	}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I missed that one when adapting the code, but definitely that looks fishy, thanks for pointing it out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants