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

Refactor to support Ansible 2.8 #1549

Merged
merged 31 commits into from
Sep 28, 2019
Merged

Refactor to support Ansible 2.8 #1549

merged 31 commits into from
Sep 28, 2019

Conversation

jackivanov
Copy link
Collaborator

@jackivanov jackivanov commented Aug 15, 2019

Upgrades and Fixes

  • Upgrade to Ansible 2.8.3
  • Upgrade to Python 3
  • Big documentation changes

Cloud provider changes

Breaking changes

  • python virtual environment location is now .env
  • GCE: from now, the installer expects you to specify a region (eg: us-east1), instead of a zone (eg: us-east1-a).

Types of changes

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@davidemyers
Copy link
Contributor

I tried a few tests. Starting with a new Ubuntu Server 19.04 container I ran cloud deployments to Vultr and DigitalOcean. Then I created an Ubuntu Server 19.04 droplet on DigitalOcean and did a local install. All tested fine using WireGuard on iOS.

Copy link

@phaer phaer left a comment

Choose a reason for hiding this comment

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

Besides adding the api-token to the 2 places described, I had to add a tasks in roles/common/tasks/ubuntu.yaml to wait for unattended-upgrades to finish, which seemed to start as soon as the hcloud server had been provisioned:

    - name: Wait for any possibly running unattended upgrade to finish
      raw: systemd-run --property="After=apt-daily.service apt-daily-upgrade.service" --wait /bin/true
 
    - name: Install software updates

After that it worked fine.

roles/cloud-hetzner/tasks/main.yml Outdated Show resolved Hide resolved
roles/cloud-hetzner/tasks/main.yml Outdated Show resolved Hide resolved
@jackivanov
Copy link
Collaborator Author

Thanks @phaer! Somehow I missed the api tokens. I just sent another solution for the apt lock, works well.

@phaer
Copy link

phaer commented Aug 16, 2019

I just sent another solution for the apt lock, works well.
Ah yes, thanks! My ansible skills are a bit rusty, didn't think about that.

@jackivanov

This comment has been minimized.

@davidemyers
Copy link
Contributor

An Ubuntu Server 18.04 droplet local install works OK too.

@davidemyers
Copy link
Contributor

davidemyers commented Aug 16, 2019

Also, just for "fun", an Ubuntu Server 19.04 droplet local install works if you replace python with python3 in the setup instructions. 😄

@jackivanov jackivanov changed the title Bump Ansible to 2.8 and new provider Hetzner Cloud [WIP] Bump Ansible to 2.8 and new provider Hetzner Cloud Aug 16, 2019
@TC1977
Copy link
Contributor

TC1977 commented Aug 16, 2019

Update docs?

@jackivanov
Copy link
Collaborator Author

@TC1977 I would appreciate your help :) I guess, you can commit directly to this branch?

@TC1977
Copy link
Contributor

TC1977 commented Aug 16, 2019

Working on it now 😄 I can't commit directly, but I can submit a PR to this branch.

@jackivanov
Copy link
Collaborator Author

Yes, that's OK

@TC1977
Copy link
Contributor

TC1977 commented Aug 16, 2019

Ok, I think I'm all set. #1552

@davidemyers
Copy link
Contributor

davidemyers commented Aug 17, 2019

A cloud deployment from an Ubuntu Server 19.04 container to DigitalOcean using python3 works with these new DO modules.

It works if LANG=C.UTF-8 but fails if LANG="en_US.UTF-8" on this bit where the p12 password is generated:

openssl rand 8 |
      python -c 'import sys,string; chars=string.ascii_letters + string.digits + "_@"; print("".join([chars[ord(c) % 64] for c in list(sys.stdin.read())]))'

Edited to add: On Ubuntu Server 18.04 I needed to use LANG=C.

@davidemyers
Copy link
Contributor

davidemyers commented Aug 18, 2019

A cloud deployment from macOS 10.14.6 to DigitalOcean using python3 and LANG=C.UTF-8 also works.

Since I already had Homebrew installed I set up the dependencies like this:

brew install python
python3 -m pip install --upgrade virtualenv # Don't need --user

I think when the time comes to move to python3 the instructions for macOS users might want to include both using Homebrew and installing the official Python 3 package as options. Homebrew is convenient but if you're not already using it it's kind of a big dependency. Though I wonder if the official Python 3 package will require updating the certificate store like the Python 2 package does, as discussed in #1545.

Edited to add one more note about Python 3: When running a local or DO deploy on Ubuntu the only prerequisite package I needed to install was python3-virtualenv. That's a considerable reduction in required packages for those doing cloud deploys.

@jackivanov
Copy link
Collaborator Author

@davidemyers I think we need to address python3 in a separate issue

@davidemyers
Copy link
Contributor

@jackivanov I agree, I was just curious to know what already worked and thought I'd record what I found in case it's useful later.

@jackivanov jackivanov changed the title [WIP] Bump Ansible to 2.8 and new provider Hetzner Cloud Large refactor to support Ansible 2.8 Aug 21, 2019
@jackivanov jackivanov changed the title Large refactor to support Ansible 2.8 Refactor to support Ansible 2.8 Aug 21, 2019
@jackivanov jackivanov changed the title Refactor to support Ansible 2.8 [WIP] Refactor to support Ansible 2.8 Aug 22, 2019
@jackivanov
Copy link
Collaborator Author

Actually, I'd like to switch to python3 in this pr, so still work in progress

@davidemyers
Copy link
Contributor

I'm not a Python expert, but I think PEP 538 explains the issue with generating the p12 password in Python 3. This works at the command line on 18.04, 19.04, and macOS:

openssl rand 8 | LANG=C python3 -c 'import sys,string; chars=string.ascii_letters + string.digits + "_@"; print("".join([chars[ord(c) % 64] for c in list(sys.stdin.read())]))'

I haven't tried it this way yet when invoked from Ansible.

@jackivanov jackivanov force-pushed the ansible-2.8 branch 2 times, most recently from 476420e to ec1c319 Compare August 22, 2019 15:33
@davidemyers
Copy link
Contributor

algo needs env -> .env. After being reverted, I guess.

@bhawkins
Copy link
Contributor

I just installed from this branch on WSL, though I had to patch an Ansible script:

$ diff -Naur .env/lib/python3.5/site-packages/ansible/modules/cloud/digital_ocean/di
gital_ocean_sshkey.py{.orig,}
--- .env/lib/python3.5/site-packages/ansible/modules/cloud/digital_ocean/digital_ocean_sshkey.py.orig   2019-08-31 15:01:22.606761500 -0700
+++ .env/lib/python3.5/site-packages/ansible/modules/cloud/digital_ocean/digital_ocean_sshkey.py        2019-08-31 15:02:23.758253300 -0700
@@ -107,7 +107,7 @@
                 return json.loads(self.info["body"])
             return None
         try:
-            return json.loads(self.body)
+            return json.loads(self.body.decode())
         except ValueError:
             return None

@jackivanov
Copy link
Collaborator Author

jackivanov commented Sep 2, 2019

It appears that the minimum required version of python should be 3.6, and it seems like ubuntu 16.04 is incompatible now

@davidemyers
Copy link
Contributor

You should also remove the sentence that starts with "On Ubuntu 16.04 LTS ..." that I recently added to the README.

@jackivanov jackivanov added this to the 1.2 milestone Sep 6, 2019
@jackivanov jackivanov added the 1.2 label Sep 6, 2019
@davidemyers
Copy link
Contributor

This branch works again without library/digital_ocean_droplet.py.

@jackivanov jackivanov changed the title [WIP] Refactor to support Ansible 2.8 Refactor to support Ansible 2.8 Sep 10, 2019
@jackivanov jackivanov requested review from dguido and removed request for dguido September 10, 2019 08:30
else:
items = []
return_value = {'resources': items}
module.exit_json(**return_value)
Copy link

Choose a reason for hiding this comment

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

Could this be simplified to the following?:

module.exit_json(**dict(resources=items.get('items', [])))

return return_if_object(module, response)


def query_options(filters):
Copy link

Choose a reason for hiding this comment

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

I think we could make this a little more concise with list comprehensions:

def query_options(filters):
    if not filters:
        return ''
    elif len(filters) == 1:
        return filters[0]
    else:
        return ' '.join(
            filter if (filter.startswith('(') and filter.endswith(')'))
                   else f"({filter})"
            for filter in filters
        )

Copy link

Choose a reason for hiding this comment

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

Actually, the first two cases are implicitly handled if we turn it into a generator:

def query_options(filters):
    return ' '.join(
        filter if (filter.startswith('(') and filter.endswith(')'))
               else f"({filter})"
        for filter in filters
    )


def return_if_object(module, response):
# If not found, return nothing.
if response.status_code == 404:
Copy link

Choose a reason for hiding this comment

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

we can merge these together:

if response.status_code in (404, 204,):
    return None

@squirrel532 squirrel532 mentioned this pull request Sep 21, 2019
Copy link
Contributor

@reaperhulk reaperhulk 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 your contribution! I have sanity checked this patch and tried to look through it. To the extent that it's possible to review this looks okay, but in the future it would be much easier to do a thorough review job without putting so many distinct changes in a PR.

Ideally each of the changes listed in this PR would have been a separate PR, so instead of one 2000 line diff we'd be looking at ~8 separate PRs, each with manageable diff sizes.

@btonic provided some review feedback that it would be nice to see in a followup PR as well, but for now we'll merge the changes. Thanks again for your work!

@reaperhulk reaperhulk merged commit 8bdd99c into master Sep 28, 2019
@dguido dguido deleted the ansible-2.8 branch September 28, 2019 00:19
jackivanov added a commit that referenced this pull request Oct 31, 2019
* bump ansible to 2.8.3

* DigitalOcean: move to the latest modules

* Add Hetzner Cloud

* Scaleway and Lightsail fixes

* lint missing roles

* Update roles/cloud-hetzner/tasks/main.yml

Add api_token

Co-Authored-By: phaer <[email protected]>

* Update roles/cloud-hetzner/tasks/main.yml

Add api_token

Co-Authored-By: phaer <[email protected]>

* Try to run apt until succeeded

* Scaleway modules upgrade

* GCP: Refactoring, remove deprecated modules

* Doc updates (#1552)

* Update README.md

Adding links and mentions of Exoscale aka CloudStack and Hetzner Cloud.

* Update index.md

Add the Hetzner Cloud to the docs index

* Remove link to Win 10 IPsec instructions

* Delete client-windows.md

Unnecessary since the deprecation of IPsec for Win10.

* Update deploy-from-ansible.md

Added sections and required variables for CloudStack and Hetzner Cloud.

* Update deploy-from-ansible.md

Added sections for CloudStack and Hetzner, added req variables and examples, mentioned environment variables, and added links to the provider role section.

* Update deploy-from-ansible.md

Cosmetic changes to links, fix typo.

* Update GCE variables

* Update deploy-from-script-or-cloud-init-to-localhost.md

Fix a finer point, and make variables list more readable.

* update azure requirements

* Python3 draft

* set LANG=c to the p12 password generation task

* Update README

* Install cloud requirements to the existing venv

* FreeBSD fix

* env->.env fixes

* lightsail_region_facts fix

* yaml syntax fix

* Update README for Python 3 (#1564)

* Update README for Python 3

* Remove tabs and tweak instructions

* Remove cosmetic command indentation

* Update README.md

* Update README for Python 3 (#1565)

* DO fix for "found unpermitted parameters: id"

* Verify Python version

* Remove ubuntu 16.04 from readme

* Revert back DigitalOcean module

* Update deploy-from-script-or-cloud-init-to-localhost.md

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