Skip to content

WIP(universe): add ansible module - #1653

Closed
PaulBarrie wants to merge 1 commit into
dagger:mainfrom
PaulBarrie:feature/universe/ansible
Closed

PaulBarrie wants to merge 1 commit into
dagger:mainfrom
PaulBarrie:feature/universe/ansible

Conversation

@PaulBarrie

Copy link
Copy Markdown
Contributor

This PR aims to implement an universe module in order to run ansible playbooks with dagger.

There are two steps in order to run a playbook:

  1. Call the #Ansible struct which installs ansible in the required version and load the specified config file
  2. Call the #Playbookstruct which runs the playbook with the specified options

Questions

  • I didn't find another way to load a default config variable than storing it in a long string variable. Maybe storing it in a gist and curl it might be lighter?

  • There might some Ansible use cases which are not handled by the module. Let me know if you see some options which should be added.

  • I'm not sure at all about the tests: I've added a @test at the end of the universe.bats but idk if there are other things to add in order to properly run tests on the module.

  • Moreover, up to now the test just check that the expected output of the Ansible playbook. Should it also test that the right config and inventory are loaded?

@grouville

grouville commented Feb 23, 2022 •

Copy link
Copy Markdown
Member

Thanks for this awesome contribution! 😇
I actually have a use-case requiring this definition, so it's perfect 😎

I'll take some time to test it on my side later in the afternoon, did you manage to run them locally successfully ?

@grouville

Copy link
Copy Markdown
Member

Hi @PaulBarrie,
I managed to fix your issues locally. Could you please give me rights on your fork, so that I can push them ?

  • Otherwise, to sum up, I encountered several small issues: the pkg/universe.dagger.io folder is for the europa version of dagger (next release). You need to move them to pkg/alpha.dagger.io. That's why the CI fails.

  • After moving the pkg/universe.dagger.io/ansible folder inside pkg/alpha.dagger.io, you need to create a new environment: dagger new ansible -p ansible/tests

  • You need to set the keys, from the pkg/alpha.dagger.io/ansible/tests folder:

dagger input text  Inventory.file -f src/hosts -e ansible
dagger input dir SSH.keysSource ssh -e ansible
dagger input dir PlaybookConfig.source src -e ansible

You need to change your test that way:

@test "ansible" {
  run dagger -e ansible up
  assert_success
  assert_output --partial "Hello Ansible, here is Dagger"
}

If you do that, the tests will pass locally: make universe-test. Once done, we will need to override your values.yml because you don't have the CI key

@grouville grouville left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As said in the main comment before. The package is not at the proper location.

I would first move it and make the changes requested from the first comment. Then after do these changes in the code.

Overall, it's very good work. These changes will improve things, but it's a strong base

Comment on lines 50 to 58

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is it there 2 times ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question, shouldn't be :)

Comment thread pkg/alpha.dagger.io/universe.bats Resolved
Comment on lines 32 to 42

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are all these packages necessary to install Ansible ? Can you please show me related doc ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Remember got issues to install (and run) ansible without these packages with pip (to get the specified version on alpine). I will dig deeper on this topic.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of making it optional

configFile?: string @dagger(input)

Why not defaulting to either

configFile: *#DefaultAnsibleConfig | string @dagger(input)

This would remove the necessity of:

_configFileContent: #DefaultAnsibleConfig

 	if setup.configFile != _|_ {
 		_configFileContent: setup.configFile
 	}
 	```

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes much better :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

By convention, we almost never name our variables in capital

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Since the naming convention seems to be Pascal case for variables and since "ssh" is an acronym, should I rather name it Ssh or ssh?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would go with the second one

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having these vars as a single string seems weird (first impression). Why not making it a list of strings ?

extraVars: *null | string @dagger(input)

to

extraVars: [string] @dagger(input)

You then check the len

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems better indeed, just have to concatenate list afterward.

Comment on lines 69 to 72

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

From what I understand here, you're just mounting the config.ansibleConfig file using the env vars ?
There is the op.#Writefile that you can directly leverage. You will then be able to skip this step.

op.#WriteFile & {
	content: file.content
	mode:    file.mode
	"dest":  dest
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually it mounts the inventory file at the location specified into the config file.

@netlify

netlify Bot commented Feb 24, 2022 •

Copy link
Copy Markdown

@PaulBarrie

Copy link
Copy Markdown
Contributor Author

Hi @grouville :)

Thanks for your review !

Took some of your comments, some are still underway.

I gave you permissions on my fork.

@grouville

Copy link
Copy Markdown
Member

Hi @grouville :)

Thanks for your review !

Took some of your comments, some are still underway.

I gave you permissions on my fork.

Perfect 😇
Thanks, I'll only interact at the end to encrypt the env file with our CI key

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Mar 18, 2022
@gerhard gerhard mentioned this pull request Mar 18, 2022
@shykes

shykes commented Apr 1, 2022

Copy link
Copy Markdown
Contributor

Hi @PaulBarrie , we just added an experimental namespace to universe.dagger.io, to allow merging contributions such as yours sooner, without rushing it to an official status. See #1991 and #1962 for what we've done for the Pulumi package contributed by @rawkode.

If you're still interested, we'd love to get your contribution merged (in your own experimental namespace) so that other developers can try it right away, and iterate from there, in the hope of getting to an official ansible package eventually.

Let me know and we can give you next steps (it's easy, mostly renaming your files to a new location).

Thanks and sorry for the slow response the first time around!

@PaulBarrie

Copy link
Copy Markdown
Contributor Author

Hi @shykes,
It's ok for me, I will have time in a week to handle this. I will take a look at the Pulumi package and try to do the same for Ansible :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants