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

ansible: add Pipfile and make python3 compatible #1399

Closed
wants to merge 1 commit into from

Conversation

refack
Copy link
Contributor

@refack refack commented Jul 12, 2018

  1. Add Pipfile to describe dependencies
  2. add needed git ignore rules
  3. make code PEP8 compliant and add .flake8
  4. make code python3 (3.7 specifically) compatible

@refack
Copy link
Contributor Author

refack commented Jul 12, 2018

Ref: #1389

@refack
Copy link
Contributor Author

refack commented Jul 12, 2018

P.S. workflow is:

  1. Setup
> cd ansible
> pipenv install
  1. excecute
> pipenv shell
(venv)> ansible-playbook ...
or
> pipenv run ansible-playbook ...

@maclover7
Copy link
Contributor

@refack Would you be able to update ansible/README.md and the other docs with the new pipenv commands?

gibfahn

This comment was marked as off-topic.

@rvagg
Copy link
Member

rvagg commented Nov 28, 2018

I don't understand any of this, I just know ansible is broken for me on my mac

does it have to be so heavy-weight? switching to items() in filter.py fixes my immediate issue. Why do we need these dependencies and what is PEP8 and why do we need it? Is there a minimal version of this?

@cclauss
Copy link
Contributor

cclauss commented Jan 30, 2019

Rebase?

@refack
Copy link
Contributor Author

refack commented Mar 14, 2019

Code has been reworked and rebased.
Some stuff that "work for me":

ansible -m ping test*

ansible-playbook -vvv playbooks/upgrade-packages.yml -l test-rackspace-ubuntu1604-x64-2

ansible-playbook -vvvv playbooks/jenkins/worker/create.yml -l test-rackspace-ubuntu1604-x64-2 --check

infra-*
!node-www.tmpl
Copy link
Member

Choose a reason for hiding this comment

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

what's this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're tracking this file https://github.com/nodejs/build/blob/master/setup/www/host_vars/node-www.tmpl
(keeping it ignored, make my IDE angry)

@rvagg
Copy link
Member

rvagg commented Mar 15, 2019

So, with this we'd need to execute ansible from inside pipenv and not bother with having a global ansible package?

Can you explain the logic of this for me and what the dependencies are for?

@rvagg
Copy link
Member

rvagg commented Mar 15, 2019

And: does this crate necessary dependencies? Will running the playbooks directly with ansible-playbook even on a machine with Python 3 still work or must we use the steps above? If so, maybe we could script it? ./run-playbook.sh .....

@refack
Copy link
Contributor Author

refack commented Mar 15, 2019

So, with this we'd need to execute ansible from inside pipenv and not bother with having a global ansible package?

Can you explain the logic of this for me and what the dependencies are for?

It's an alternative approach.
tl;dr python out-of-the-box works with global dependencies.
Then came virtualenv that wraps python with some monkey-patches so it first looks for dependencies in a local dependency store.
Then came pipenv and the Pipefile that allows for a workflow similar to npm (i.e. dependencies stored locally by default, and pip install installs locally and updates the Pipfile).

And: does this crate necessary dependencies? Will running the playbooks directly with ansible-playbook even on a machine with Python 3 still work or must we use the steps above? If so, maybe we could script it? ./run-playbook.sh .....

It's still possible to use global dependencies just as before. Or we can use npm run style recipes that allow doing things like:

pipenv run playbook [what [ever [args]]]

example:
https://github.com/refack/GYP/blob/86ab71caad4640dcc3ec572c2118a1ce3f24150f/Pipfile#L12-L14
used as:
https://github.com/refack/GYP/blob/master/.travis.yml#L35

@rvagg
Copy link
Member

rvagg commented Mar 15, 2019

OK, as long as it's documented I could live with it. I'll try it out soon on some of my known-breaking Python 3 Ansible tasks.

@rvagg
Copy link
Member

rvagg commented Mar 17, 2019

this worked on a freebsd and ubuntu 14.04 reprovision but the problem I have with ccache jinja2 scripting persists:

fatal: [test-requireio_kahwee-debian9-arm64_pi3-1]: FAILED! => {"msg": "Unexpected templating type error occurred on ({{ ccache_html_content.stdout | regex_findall('ccache-[0-9]+.[0-9]+(?:.[0-9]+)*.tar.gz') | map('regex_replace', 'ccache-') | map('regex_replace', '.tar.gz') | list | latest_version }}): '<' not supported between instances of 'map' and 'map'"}

@cclauss
Copy link
Contributor

cclauss commented Mar 17, 2019

You could try putting | list | in between the two calls to map(). Python 3 often creates generators instead of lists so perhaps forcing the results of the first map() call into a list will placate Jinja2.

Update: Did not work at #1674 :-(

@refack
Copy link
Contributor Author

refack commented Mar 17, 2019

'<' not supported between instances of 'map' and 'map'"

forcing the results of the first map() call into a list will placate Jinja2.

👍 make sense.

anyway.
I'll try to move that super-filter out of the template and into code

'macstadium', 'marist', 'mininodes', 'msft', 'osuosl',
'rackspace', 'requireio', 'scaleway', 'softlayer', 'voxer',
'packetnet', 'nearform')
# taken from nodejs/node.git: ./configure

Choose a reason for hiding this comment

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

I don't think they are in sync anymore. https://github.com/nodejs/node/blob/ed2c6965d2f901f3c786f9d24bcd57b2cd523611/configure.py#L48-L49

valid_arch = ('arm', 'arm64', 'ia32', 'ppc',
              'ppc64', 'x32','x64', 'x86', 'x86_64', 's390', 's390x')

parser.add_argument('--host', action='store')
args = parser.parse_args()

# parser = argparse.ArgumentParser()

Choose a reason for hiding this comment

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

Why are we checking in commented code?

@@ -6,9 +6,9 @@
with open('out/index.csv') as index:
index_csv = filter(lambda line: line, index.read().split('\n'))

# noqa

Choose a reason for hiding this comment

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

Is this comment incomplete?

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM: This flake8 linter directive will silence the linter as discussed at
http://flake8.pycqa.org/en/3.7.7/user/violations.html#in-line-ignoring-errors

@cclauss
Copy link
Contributor

cclauss commented Jul 29, 2019

@refack Can you please go through the comments (esp. #1399 (comment)) and make any required updates? It would be a big help to have pipenv in place.

pipenv has the effect of running Python in its own virtualenv on the user's machine which means that the Python version is more predictable and that no outside dependencies are installed.

Copy link
Contributor

@cclauss cclauss left a comment

Choose a reason for hiding this comment

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

Let's move forward with this to ease the transition to Python 3.

@Trott
Copy link
Member

Trott commented Aug 19, 2019

@refack Can you please go through the comments (esp. #1399 (comment)) and make any required updates? It would be a big help to have pipenv in place.

@cclauss Unfortunately, @refack has not been active lately. My hope is he's just taking a break from Node.js stuff and hasn't left entirely, but either way, it would probably be best for someone to take this over and finish it. Are you up for doing that?

* add Pipfile
* de-lint with `flake8`
@Trott
Copy link
Member

Trott commented Sep 27, 2019

Rebased to eliminate conflicts and force-pushed. @cclauss @refack

@cclauss
Copy link
Contributor

cclauss commented Sep 30, 2019

My sense is that this can be closed unless @refack has objections. I like the idea of automating the creation of virtualenvs for our builds to take place in and pipenv would deliver that. However @sam-github and I agreed that there might be compatibility issues on non-mainstream Win/Mac/Linux so we should delay that experimentation until after we have Python 3 working.

@Trott
Copy link
Member

Trott commented Sep 30, 2019

My sense is that this can be closed unless @refack has objections. I like the idea of automating the creation of virtualenvs for our builds to take place in and pipenv would deliver that. However @sam-github and I agreed that there might be compatibility issues on non-mainstream Win/Mac/Linux so we should delay that experimentation until after we have Python 3 working.

In that case, I"m going to close this, but @refack or anyone else should feel absolutely free to re-open it if they think that's the wrong move.

@Trott Trott closed this Sep 30, 2019
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.

7 participants