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

Add support for switching between nodejs versions (upgrade/downgrade) #222

Merged
merged 6 commits into from
Jan 29, 2020

Conversation

cognifloyd
Copy link
Member

Add some tasks to ensure the nodesource repo is up-to-date before attempting to install nodejs.
Thus, if this playbook is run against a machine that already has the repo, it will safely upgrade
the repo so that the nodejs install task doesn't complain about not finding the version requested.

This also sets update_cache on upgrade so that the newer nodejs rpm becomes available for install.

@cognifloyd
Copy link
Member Author

Checks are green. Please review and merge.

@cognifloyd cognifloyd requested a review from arm4b January 15, 2020 20:06
@cognifloyd cognifloyd changed the title Upgrade nodejs repo Add ability to upgrade nodejs repo idempotently Jan 15, 2020
@pull-request-size pull-request-size bot added the size/S PR that changes 10-29 lines. Very easy to review. label Jan 15, 2020
@arm4b
Copy link
Member

arm4b commented Jan 16, 2020

Thanks for the PR.

What means under the "ensure the nodesource repo is up-to-date before attempting to install nodejs"? Why the nodejs repository needs to be deleted first?

Do you mean switching between major nodejs versions maybe?
Can you describe your use case in more detail with steps to reproduce?

@cognifloyd
Copy link
Member Author

cognifloyd commented Jan 16, 2020

Yes, this is for upgrading between major nodejs versions.

This is part of the nodesource-el.repo file on a CentOS 7 box for NodeJS 4.x installed by nodesource-release-el7-1.noarch.rpm:

baseurl=https://rpm.nodesource.com/pub_4.x/el/7/$basearch

And nodesource-el7.repo on a different CentOS 7 box for NodeJS 10.x installed by nodesource-release-el7-1.noarch.rpm:

baseurl=https://rpm.nodesource.com/pub_10.x/el/7/$basearch

Each major nodejs version uses a different URL. But, both repo versions are installed with a release RPM file that has the same version. The only way to tell which one is installed is to inspect the installed repo file.

If you do not adjust the repo when upgrading to a new major nodejs version, yum will not be able to find the appropriate rpms.

@cognifloyd
Copy link
Member Author

Rebased, updated the task name, and added some explanatory comments in the tasks file to explain why this is required.

@cognifloyd cognifloyd changed the title Add ability to upgrade nodejs repo idempotently Fix upgrading between major nodejs versions by updating yum repo release rpm Jan 16, 2020
cognifloyd added a commit to theatro/ansible-st2 that referenced this pull request Jan 16, 2020
@cognifloyd cognifloyd closed this Jan 21, 2020
@cognifloyd cognifloyd reopened this Jan 22, 2020
@nmaludy nmaludy self-requested a review January 22, 2020 01:52
Copy link
Member

@nmaludy nmaludy left a comment

Choose a reason for hiding this comment

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

Thoughts on my dumb idea?

roles/StackStorm.nodejs/tasks/nodejs_yum.yml Outdated Show resolved Hide resolved
@nmaludy
Copy link
Member

nmaludy commented Jan 22, 2020

@cognifloyd ignore my banter about the template file, i think keeping it as an RPM is the right approach... think the biggest thing here is making the behavior consistent across RHEL + Debian and it should be good to go!

The nodesource repo rpm causes problems if a node.js major version
upgrade is required (such as from 4.x to 10.x) because the version
number of the repo version does not change even though the node.js
version in the repo file changes.

Rather than hacking around that problematic rpm, we use the
yum_repository ansible module to install the repo.
@cognifloyd cognifloyd changed the title Fix upgrading between major nodejs versions by updating yum repo release rpm Use yum_repository for nodesource repo install Jan 22, 2020
@cognifloyd
Copy link
Member Author

Switched to the yum_repository module to drop the hacky repo upgrade tasks. Excellent suggestion. Thanks @nmaludy

Copy link
Member

@nmaludy nmaludy left a comment

Choose a reason for hiding this comment

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

Onw small question

roles/StackStorm.nodejs/tasks/nodejs_yum.yml Outdated Show resolved Hide resolved
@punkrokk
Copy link
Member

punkrokk commented Jan 22, 2020

@cognifloyd re: NPM repos -> I discovered this approach for the st2-chatops packaging container - I wonder which way we may wish to consider standardizing on.

https://github.com/StackStorm/st2chatops/blob/b6bdbb72064ca5630a3dbeaff7c7f02ce3a3be21/packagingenv/centos8/Dockerfile

@cognifloyd
Copy link
Member Author

I'm not sure we can harmonize much between the dockerfiles and config management (at least ansible config management) because the goals of the install methods are different.

Ansible strives for idempotence wherever possible. Running scripts that just "do" things is typically anathema to that goal. The script gets things installed, but you cannot safely re-run a playbook that runs such a script. As a script does not report whether or not it changes things, ansible assumes that running scripts always changes things. So you also cannot use a playbook that runs such a script to audit the installation.

But, Dockerfiles are glorified scripts that save state after each RUN step. There is no idempotence or granular change tracking. So just running a script is a perfectly sane thing to do to minimize the number of docker layers while keeping the steps as reusable as possible. So, I don't see much benefit to changing the dockerfile here.

Some things do warrant standardization across installation methods, so that they each install the same features or versions for example. But, I don't think standardizing beyond "install node.js" is worth the effort in this case.

@punkrokk
Copy link
Member

punkrokk commented Jan 22, 2020 via email

@cognifloyd
Copy link
Member Author

@punkrokk Ah. I don't have a CentOS 8 machine handy, but I believe ansible_facts.pkg_mgr is dnf on CentOS 8. So we will need to add a new nodejs_dnf.yaml file to the nodejs role. We can then use the dnf module to install the package stream/modularity (not sure on the term here) with something like name: "@nodejs:{{ nodejs_major_version }}".

@arm4b
Copy link
Member

arm4b commented Jan 22, 2020

CentOS8 is a topic for a dedicated PR for which we have a TODO issue: #248 and out of scope of work in this PR.
In fact, Ansible playbooks doesn't even have Ubuntu 18 support yet: #249

I like how the code ended in this PR, thanks @nmaludy for review! 👍 It also needs manual cycle to test the node repo upgrade behavior end2end to identify any corner cases before merging.

@nmaludy
Copy link
Member

nmaludy commented Jan 22, 2020

@cognifloyd can you please run this manually to do the upgrade 2-3 times and report back?

Thanks!

@arm4b
Copy link
Member

arm4b commented Jan 22, 2020

I think @cognifloyd as contributor already ran his code during development.

However in PR both contributor and reviewer are responsible for the merged code. I would prefer if reviewer does additional few checks too if it's not simplest change.
The reason is as we all think different, people might do different things in different environments to achieve the same end result. And that's awesome. Rare bugs and corner cases are discovered during the exploratory testing.

Once we'll do a StackStorm release,- besides of good amount of automated tests (testing knowns) we all do extensive manual checking trying random things based on changelog (testing unknowns) for several days. That's usually a source of good amount of bugs caught before landing into production version.

Sometimes we test in production too :), but I'd like us to keep the quality bar as @StackStorm/TSC best effort.

@cognifloyd
Copy link
Member Author

cognifloyd commented Jan 23, 2020

Using the Vagrantfile that came with ansible-st2, I changed the default box to CentOS 7:

  VIRTUAL_MACHINES.each do |name, cfg|
    #config.vm.define name, autostart: (name == :ubuntu16) do |vm_config|
    config.vm.define name, autostart: (name == :centos7) do |vm_config|

And added some extra_vars to go back to the last st2 version that used nodejs 4:

        ansible.playbook = "stackstorm.yml"
        ansible.extra_vars = {
          st2_version: "2.9.3",
          st2mistral_version: "2.9.3",
          st2chatops_version: "2.9.3",
          nodejs_major_version: "4"
        }
      end

I then destroyed the vagrant box and did vagrant up.
Then I commented out those extra vars and re-provisioned with vagrant provision --provision-with ansible_local (thus switching to the latest st2 and nodejs).
The nodesource repo and nodejs upgraded successfully.

@cognifloyd
Copy link
Member Author

More background on why this is needed.
I reverted to ansible-st2 v0.9.1, and made similar changes to use centos7 and these extra_vars:

        ansible.extra_vars = {
          st2_version: "2.9.3",
          st2mistral_version: "2.9.3",
          st2chatops_version: "2.9.3"
        }

In v0.9.1, node.js defaults to v6.

Bringing up the box, everything installed fine. The nodesource repo was installed with the rpm, and the repo file is: /etc/yum.repos.d/nodesource-el.repo (newer versions use el7 instead of just el in the filename).

Then I removed my ansible extra_vars and reprovision with the same older version of the playbook.

nodejs does not update (it stays at version 6 as that is the default in that v0.9.1 of this repo):

TASK [nodejs : Add nodesource repo] ********************************************
ok: [centos7] => {"changed": false, "msg": "", "rc": 0, "results": ["nodesource-release-el7-1.noarch providing /home/vagrant/.ansible/tmp/ansible-tmp-1580249855.21-57198950370043/nodesource-release-el7-1.noarchMcDqdt.rpm is already installed"]}

TASK [nodejs : Install nodejs] *************************************************
ok: [centos7] => {"attempts": 1, "changed": false, "msg": "", "rc": 0, "results": ["2:nodejs-6.17.1-1nodesource.x86_64 providing nodejs-6.* is already installed"]}

And as expected installing st2chatops fails because nodejs>=8.0 is not installed:

fatal: [centos7]: FAILED! => {"attempts": 5, "changed": true, "changes": {"installed": [], "updated": [["st2chatops", "3.1.0-2.x86_64 from StackStorm_stable"]]}, "msg": "Error: Package: st2chatops-3.1.0-2.x86_64 (StackStorm_stable)\n           Requires: nodejs >= 2:8.0\n           Installed: 2:nodejs-6.17.1-1nodesource.x86_64 (@nodesource)\n               nodejs = 2:6.17.1-1nodesource\n           Available: nodejs-6.0.0-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 6.0.0-1nodesource.el7.centos\n           Available: nodejs-6.1.0-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 6.1.0-1nodesource.el7.centos\n           Available: nodejs-6.2.0-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 6.2.0-1nodesource.el7.centos\n           Available: nodejs-6.2.1-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 6.2.1-1nodesource.el7.centos\n           Available: nodejs-6.2.2-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 6.2.2-1nodesource.el7.centos\n           Available: 1:nodejs-6.3.0-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 1:6.3.0-1nodesource.el7.centos\n           Available: 1:nodejs-6.3.1-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 1:6.3.1-1nodesource.el7.centos\n           Available: 1:nodejs-6.4.0-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 1:6.4.0-1nodesource.el7.centos\n           Available: 1:nodejs-6.6.0-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 1:6.6.0-1nodesource.el7.centos\n           Available: 1:nodejs-6.7.0-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 1:6.7.0-1nodesource.el7.centos\n           Available: 1:nodejs-6.17.1-1.el7.x86_64 (epel)\n               nodejs = 1:6.17.1-1.el7\n           Available: 2:nodejs-6.8.0-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.8.0-1nodesource.el7.centos\n           Available: 2:nodejs-6.8.1-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.8.1-1nodesource.el7.centos\n           Available: 2:nodejs-6.9.0-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.9.0-1nodesource.el7.centos\n           Available: 2:nodejs-6.9.1-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.9.1-1nodesource.el7.centos\n           Available: 2:nodejs-6.9.2-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.9.2-1nodesource.el7.centos\n           Available: 2:nodejs-6.9.3-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.9.3-1nodesource.el7.centos\n           Available: 2:nodejs-6.9.4-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.9.4-1nodesource.el7.centos\n           Available: 2:nodejs-6.9.5-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.9.5-1nodesource.el7.centos\n           Available: 2:nodejs-6.10.0-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.10.0-1nodesource.el7.centos\n           Available: 2:nodejs-6.10.1-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.10.1-1nodesource.el7.centos\n           Available: 2:nodejs-6.10.2-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.10.2-1nodesource.el7.centos\n           Available: 2:nodejs-6.10.2-2nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.10.2-2nodesource.el7.centos\n           Available: 2:nodejs-6.10.3-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.10.3-1nodesource.el7.centos\n           Available: 2:nodejs-6.11.0-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.11.0-1nodesource.el7.centos\n           Available: 2:nodejs-6.11.1-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.11.1-1nodesource.el7.centos\n           Available: 2:nodejs-6.11.2-1nodesource.el7.centos.x86_64 (nodesource)\n               nodejs = 2:6.11.2-1nodesource.el7.centos\n           Available: 2:nodejs-6.11.3-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.11.3-1nodesource\n           Available: 2:nodejs-6.11.4-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.11.4-1nodesource\n           Available: 2:nodejs-6.11.5-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.11.5-1nodesource\n           Available: 2:nodejs-6.12.0-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.12.0-1nodesource\n           Available: 2:nodejs-6.12.1-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.12.1-1nodesource\n           Available: 2:nodejs-6.12.2-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.12.2-1nodesource\n           Available: 2:nodejs-6.13.0-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.13.0-1nodesource\n           Available: 2:nodejs-6.13.1-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.13.1-1nodesource\n           Available: 2:nodejs-6.14.0-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.14.0-1nodesource\n           Available: 2:nodejs-6.14.1-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.14.1-1nodesource\n           Available: 2:nodejs-6.14.2-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.14.2-1nodesource\n           Available: 2:nodejs-6.14.3-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.14.3-1nodesource\n           Available: 2:nodejs-6.14.4-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.14.4-1nodesource\n           Available: 2:nodejs-6.15.0-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.15.0-1nodesource\n           Available: 2:nodejs-6.15.1-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.15.1-1nodesource\n           Available: 2:nodejs-6.16.0-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.16.0-1nodesource\n           Available: 2:nodejs-6.17.0-1nodesource.x86_64 (nodesource)\n               nodejs = 2:6.17.0-1nodesource\n", "obsoletes": {"grub2": {"dist": "x86_64", "repo": "@anaconda", "version": "1:2.02-0.65.el7.centos.2"}, "grub2-tools": {"dist": "x86_64", "repo": "@anaconda", "version": "1:2.02-0.65.el7.centos.2"}}, "rc": 1, "results": ["Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: repos.dfw.quadranet.com\n * epel: d2lzkl7pfhq30w.cloudfront.net\n * extras: mirror.dal.nexril.net\n * updates: repos.dfw.quadranet.com\nResolving Dependencies\n--> Running transaction check\n---> Package st2chatops.x86_64 0:2.9.3-1 will be updated\n---> Package st2chatops.x86_64 0:3.1.0-2 will be an update\n--> Processing Dependency: nodejs >= 2:8.0 for package: st2chatops-3.1.0-2.x86_64\n--> Finished Dependency Resolution\n You could try using --skip-broken to work around the problem\n You could try running: rpm -Va --nofiles --nodigest\n"]}

Then I checkout master (again dropping my ansible extra_vars, but still targeting centos7), run vagrant rsync to copy master into the vm and re-provision.

The nodesource repo does not update and installing nodejs-10.* fails:

TASK [StackStorm.nodejs : Add nodesource repo] *********************************
ok: [centos7] => {"changed": false, "msg": "", "rc": 0, "results": ["nodesource-release-el7-1.noarch providing /home/vagrant/.ansible/tmp/ansible-tmp-1580252149.38-645215070533/nodesource-release-el7-1.noarchlrKuxm.rpm is already installed"]}

TASK [StackStorm.nodejs : Install nodejs] **************************************
fatal: [centos7]: FAILED! => {"attempts": 5, "changed": false, "msg": "No package matching 'nodejs-10.*' found available, installed or updated", "rc": 126, "results": ["No package matching 'nodejs-10.*' found available, installed or updated"]}

Then, I switched to the upgrade_nodejs branch (this PR), rsynced the repo, and re-ran the provisioner.

Though the repo seems to update, it fails to use the newer repo because the repo installed by the rpm is loaded first. So we also need to remove the RPM:

TASK [StackStorm.nodejs : Add nodesource repo] *********************************
changed: [centos7] => {"changed": true, "repo": "nodesource", "state": "present"}

TASK [StackStorm.nodejs : Install nodejs] **************************************
fatal: [centos7]: FAILED! => {"attempts": 5, "changed": false, "msg": "No package matching 'nodejs-10.*' found available, installed or updated", "rc": 126, "results": ["No package matching 'nodejs-10.*' found available, installed or updated"]}

Here's the repo file list:

[vagrant@ansible-st2-centos7 ~]$ ls /etc/yum.repos.d/nodesource-el*
/etc/yum.repos.d/nodesource-el7.repo  /etc/yum.repos.d/nodesource-el.repo

I will add a task to remove the rpm and then I'll re-run.

@cognifloyd
Copy link
Member Author

K. That removed the repo rpm, but the cache was out-of-date, so it did not find the nodejs rpm. So, we need a register on both repo tasks to make sure if either of them changes, the cache gets updated when installing nodejs.

TASK [StackStorm.nodejs : Remove nodesource repo rpm] **************************
changed: [centos7] => {"changed": true, "changes": {"removed": ["nodesource-release-el7-1.noarch"]}, "msg": "Repository nodesource is listed more than once in the configuration\n", "rc": 0, "results": ["Loaded plugins: fastestmirror\nResolving Dependencies\n--> Running transaction check\n---> Package nodesource-release.noarch 0:el7-1 will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package                   Arch          Version         Repository        Size\n================================================================================\nRemoving:\n nodesource-release        noarch        el7-1           installed        3.1 k\n\nTransaction Summary\n================================================================================\nRemove  1 Package\n\nInstalled size: 3.1 k\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Erasing    : nodesource-release-el7-1.noarch                              1/1 \n  Verifying  : nodesource-release-el7-1.noarch                              1/1 \n\nRemoved:\n  nodesource-release.noarch 0:el7-1                                             \n\nComplete!\n"]}

TASK [StackStorm.nodejs : Add nodesource repo file] ****************************
ok: [centos7] => {"changed": false, "repo": "nodesource", "state": "present"}

TASK [StackStorm.nodejs : Install nodejs] **************************************
fatal: [centos7]: FAILED! => {"attempts": 5, "changed": false, "msg": "No package matching 'nodejs-10.*' found available, installed or updated", "rc": 126, "results": ["No package matching 'nodejs-10.*' found available, installed or updated"]}

@cognifloyd
Copy link
Member Author

Then I ran sudo yum install http://rpm.nodesource.com/pub_10.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm so the playbook can remove it again, then ran rsync and provision.

This time the nodesource repo and nodejs upgraded as expected:

TASK [StackStorm.nodejs : Remove nodesource repo rpm] **************************
changed: [centos7] => {"changed": true, "changes": {"removed": ["nodesource-release-el7-1.noarch"]}, "msg": "", "rc": 0, "results": ["Loaded plugins: fastestmirror\nResolving Dependencies\n--> Running transaction check\n---> Package nodesource-release.noarch 0:el7-1 will be erased\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package                   Arch          Version         Repository        Size\n================================================================================\nRemoving:\n nodesource-release        noarch        el7-1           installed        3.1 k\n\nTransaction Summary\n================================================================================\nRemove  1 Package\n\nInstalled size: 3.1 k\nDownloading packages:\nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\n  Erasing    : nodesource-release-el7-1.noarch                              1/1 \nwarning: /etc/yum.repos.d/nodesource-el7.repo saved as /etc/yum.repos.d/nodesource-el7.repo.rpmsave\n  Verifying  : nodesource-release-el7-1.noarch                              1/1 \n\nRemoved:\n  nodesource-release.noarch 0:el7-1                                             \n\nComplete!\n"]}

TASK [StackStorm.nodejs : Add nodesource repo file] ****************************
changed: [centos7] => {"changed": true, "repo": "nodesource", "state": "present"}

TASK [StackStorm.nodejs : Install nodejs] **************************************
changed: [centos7] => {"attempts": 1, "changed": true, "changes": {"installed": ["nodejs-10.*"]}, "msg": "", "rc": 0, "results": ["Loaded plugins: fastestmirror\nLoading mirror speeds from cached hostfile\n * base: repos.dfw.quadranet.com\n * epel: d2lzkl7pfhq30w.cloudfront.net\n * extras: mirror.teklinks.com\n * updates: repos.dfw.quadranet.com\nResolving Dependencies\n--> Running transaction check\n---> Package nodejs.x86_64 2:6.17.1-1nodesource will be updated\n---> Package nodejs.x86_64 2:10.18.1-1nodesource will be an update\n--> Processing Conflict: st2chatops-2.9.3-1.x86_64 conflicts nodejs >= 2:7.0\n--> Restarting Dependency Resolution with new changes.\n--> Running transaction check\n---> Package st2chatops.x86_64 0:2.9.3-1 will be updated\n---> Package st2chatops.x86_64 0:3.1.0-2 will be an update\n--> Finished Dependency Resolution\n\nDependencies Resolved\n\n================================================================================\n Package       Arch      Version                     Repository            Size\n================================================================================\nUpdating:\n nodejs        x86_64    2:10.18.1-1nodesource       nodesource            20 M\n st2chatops    x86_64    3.1.0-2                     StackStorm_stable     14 M\n\nTransaction Summary\n================================================================================\nUpgrade  2 Packages\n\nTotal download size: 34 M\nDownloading packages:\nNo Presto metadata available for nodesource\nNo Presto metadata available for StackStorm_stable\n--------------------------------------------------------------------------------\nTotal                                              4.5 MB/s |  34 MB  00:07     \nRunning transaction check\nRunning transaction test\nTransaction test succeeded\nRunning transaction\nDetected old npm client, removing...\n  Updating   : 2:nodejs-10.18.1-1nodesource.x86_64                          1/4 \n  Updating   : st2chatops-3.1.0-2.x86_64                                    2/4 \nwarning: /opt/stackstorm/chatops/st2chatops.env created as /opt/stackstorm/chatops/st2chatops.env.rpmnew\n  Cleanup    : st2chatops-2.9.3-1.x86_64                                    3/4 \n  Cleanup    : 2:nodejs-6.17.1-1nodesource.x86_64                           4/4 \nwarning: file /usr/lib/node_modules/npm/scripts/index-build.js: remove failed: No such file or directory\nwarning: file /usr/lib/node_modules/npm/scripts/doc-build.sh: remove failed: No such file or directory\nwarning: file /usr/lib/node_modules/npm/node_modules/which/node_modules/isexe/windows.js: remove failed: No such file or directory\nwarning: file /usr/lib/node_modules/npm/node_modules/which/node_modules/isexe/package.json: remove failed: No such file or directory\n[snip...]\n  Verifying  : 2:nodejs-10.18.1-1nodesource.x86_64                          1/4 \n  Verifying  : st2chatops-3.1.0-2.x86_64                                    2/4 \n  Verifying  : 2:nodejs-6.17.1-1nodesource.x86_64                           3/4 \n  Verifying  : st2chatops-2.9.3-1.x86_64                                    4/4 \n\nUpdated:\n  nodejs.x86_64 2:10.18.1-1nodesource        st2chatops.x86_64 0:3.1.0-2       \n\nComplete!\n"]}

@nmaludy
Copy link
Member

nmaludy commented Jan 29, 2020

I ran some tests with the Vagrant file included with ansible-st2 on this branch and everything seems good to go!

Added the following to the Vagrantfile to force an old nodejs version:

        ansible.extra_vars = {
          st2_version: "2.9.3",
          st2mistral_version: "2.9.3",
          st2chatops_version: "2.9.3",
          nodejs_major_version: "4"
        }

Then did the following

# run ansible the first time, this installs old nodejs
vagrant up centos7

# login to machine now it's up
vagrant ssh centos7

# check the nodejs repo installed (in thicase it was NodeJS 4)
cat /etc/yum.repos.d/nodesource-el7.repo

# run Ansible again without extra_vars to upgrade nodejs
cd /vagrant && PYTHONUNBUFFERED=1 ANSIBLE_FORCE_COLOR=true ansible-playbook --limit="centos7" --inventory-file=/tmp/vagrant-ansible/inventory -v stackstorm.yml

# check nodejs repo has been upgraded (nodejs 10 in this case)
cat /etc/yum.repos.d/nodesource-el7.repo

Copy link
Member

@nmaludy nmaludy left a comment

Choose a reason for hiding this comment

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

Looks great and tests worked!

@nmaludy nmaludy merged commit 86a1cec into StackStorm:master Jan 29, 2020
@arm4b arm4b changed the title Use yum_repository for nodesource repo install Add support for switching between nodejs versions (upgrade/downgrade) Jan 29, 2020
@arm4b
Copy link
Member

arm4b commented Jan 29, 2020

Thanks for PR, review and testing! 👍
Just released ansible-st2 v1.4.0 that has this enhancement included.

@cognifloyd
Copy link
Member Author

@armab you changed the title to say this supports upgrade/downgrade, but really it only supports upgrade. There's a commented out line that we need to enable on the yum: nodejs install task if we want to allow downgrading.

@cognifloyd cognifloyd deleted the upgrade_nodejs branch September 24, 2020 01:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement size/S PR that changes 10-29 lines. Very easy to review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants