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

How to enforce a specific ansible version ? #4

Open
mab27 opened this Issue May 7, 2017 · 7 comments

Comments

Projects
None yet
5 participants
@mab27
Copy link

mab27 commented May 7, 2017

mab@mab-infra:~/automation/ansible$ ansible --version
ansible 2.2.0.0
  config file = /home/mab/automation/ansible/ansible.cfg
  configured module search path = Default w/o overrides
mab@mab-infra:~/automation/ansible$ 
mab@mab-infra:~/automation/ansible$ 
mab@mab-infra:~/automation/ansible$ 
mab@mab-infra:~/automation/ansible$ sudo st2 run ansible.playbook playbook=/home/mab/automation/ansible/junos_template/pb.bgp.2.yml cwd=/home/mab/automation/ansible version=true 
.
id: 590f23547cae220956aeb00c
status: succeeded
parameters: 
  cwd: /home/mab/automation/ansible
  playbook: /home/mab/automation/ansible/junos_template/pb.bgp.2.yml
  version: true
result: 
  failed: false
  return_code: 0
  stderr: ''
  stdout: "ansible-playbook 2.3.0.0
  config file = /home/mab/automation/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]"
  succeeded: true
mab@mab-infra:~/automation/ansible$ `
mab@mab-infra:~/automation/ansible$ sudo st2 pack get ansible
+-------------+--------------------------------------------------+
| Property    | Value                                            |
+-------------+--------------------------------------------------+
| name        | ansible                                          |
| version     | 0.4.0                                            |
| author      | StackStorm, Inc.                                 |
| email       | info@stackstorm.com                              |
| keywords    | [                                                |
|             |     "ansible",                                   |
|             |     "cfg management",                            |
|             |     "configuration management"                   |
|             | ]                                                |
| description | st2 content pack containing ansible integrations |
+-------------+--------------------------------------------------+
@armab

This comment has been minimized.

Copy link
Member

armab commented May 7, 2017

At the moment there is no good mechanism to do that.

As a workaround you can fork the pack in Github and pin ansible==2.2.2.0 in requirements.txt:
https://github.com/StackStorm-Exchange/stackstorm-ansible/blob/master/requirements.txt#L1

after that install modified pack:

st2 pack install https://github.com/mab27/stackstorm-ansible

@armab armab added the question label May 7, 2017

@mab27

This comment has been minimized.

Copy link

mab27 commented May 7, 2017

Many thanks for the prompt reply.
I applied the suggestion. It helps but it doesn't fully solve the problem, and this is related to issue #5.

Below the details:

  • Removing Ansible pack (the official one):
mab@mab-infra:~/automation/ansible$ sudo st2 pack remove ansible

  [ succeeded ] unregister packs
  [ succeeded ] delete packs

+-------------+--------------------------------------------------+
| Property    | Value                                            |
+-------------+--------------------------------------------------+
| name        | ansible                                          |
| description | st2 content pack containing ansible integrations |
| version     | 0.4.0                                            |
| author      | StackStorm, Inc.                                 |
+-------------+--------------------------------------------------+
mab@mab-infra:~/automation/ansible$ sudo st2 pack install https://github.com/mab27/stackstorm-ansible

  [ succeeded ] download pack
  [ succeeded ] make a prerun
  [ succeeded ] install pack dependencies
  [ succeeded ] register pack

+-------------+--------------------------------------------------+
| Property    | Value                                            |
+-------------+--------------------------------------------------+
| name        | ansible                                          |
| description | st2 content pack containing ansible integrations |
| version     | 0.4.0                                            |
| author      | StackStorm, Inc.                                 |
+-------------+--------------------------------------------------+
  • Ansible playbook execution from ansible command (OK):
mab@mab-infra:~/automation/ansible$ sudo ansible-playbook junos_template/pb.bgp.2.yml 

PLAY [Create BGP junos configuration] ******************************************

TASK [Render BGP configuration for junos devices] ******************************
ok: [vmx2]
ok: [vmx1]

TASK [Push bgp configuration on devices] ***************************************
ok: [vmx2]
ok: [vmx1]

PLAY [Wait for peers to establish connections] *********************************

TASK [pause] *******************************************************************
Pausing for 15 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
Press 'C' to continue the play or 'A' to abort 
ok: [localhost]

PLAY [Check bgp states] ********************************************************
....
  • Verify the details st2 ansible pack is going to use:
mab@mab-infra:~/automation/ansible$ sudo st2 run ansible.playbook playbook=/home/mab/automation/ansible/junos_template/pb.bgp.2.yml cwd=/home/mab/automation/ansible version=true
.
id: 590f3c927cae220956aeb048
status: succeeded
parameters: 
  cwd: /home/mab/automation/ansible
  playbook: /home/mab/automation/ansible/junos_template/pb.bgp.2.yml
  version: true
result: 
  failed: false
  return_code: 0
  stderr: ''
  stdout: "ansible-playbook 2.2.0.0
  config file = /home/mab/automation/ansible/ansible.cfg
  configured module search path = Default w/o overrides"
  succeeded: true
mab@mab-infra:~/automation/ansible$ 
  • Ansible playbook execution using st2 (KO):
  • fatal: [vmx2]: FAILED! => {"changed": false, "failed": true, "msg": "junos-eznc >= 1.2.2 is required but does not appear to be installed. It can be installed using pip install junos-eznc"}
  • Basically the playbook is executed with API mode connection: local and it required locally a python library (junos-eznc and jxmlease). Those two libraries are installed locally, but st2 does not find them.
mab@mab-infra:~/automation/ansible$ sudo st2 run ansible.playbook playbook=/home/mab/automation/ansible/junos_template/pb.bgp.2.yml cwd=/home/mab/automation/ansible 
.
id: 590f3ca17cae220956aeb04b
status: failed
parameters: 
  cwd: /home/mab/automation/ansible
  playbook: /home/mab/automation/ansible/junos_template/pb.bgp.2.yml
result: 
  failed: true
  return_code: 2
  stderr: Executed command "/opt/stackstorm/virtualenvs/ansible/bin/ansible-playbook /home/mab/automation/ansible/junos_template/pb.bgp.2.yml"
  stdout: "
PLAY [Create BGP junos configuration] ******************************************

TASK [Render BGP configuration for junos devices] ******************************
ok: [vmx1]
ok: [vmx2]

TASK [Push bgp configuration on devices] ***************************************
fatal: [vmx2]: FAILED! => {"changed": false, "failed": true, "msg": "junos-eznc >= 1.2.2 is required but does not appear to be installed.  It can be installed using `pip install junos-eznc`"}
fatal: [vmx1]: FAILED! => {"changed": false, "failed": true, "msg": "junos-eznc >= 1.2.2 is required but does not appear to be installed.  It can be installed using `pip install junos-eznc`"}
  to retry, use: --limit @/home/mab/automation/ansible/junos_template/pb.bgp.2.retry

PLAY RECAP *********************************************************************
vmx1                       : ok=1    changed=0    unreachable=0    failed=1   
vmx2                       : ok=1    changed=0    unreachable=0    failed=1   
"
  succeeded: false
mab@mab-infra:~/automation/ansible$ pip list | grep junos
junos-eznc (2.1.1)
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
@armab

This comment has been minimized.

Copy link
Member

armab commented May 7, 2017

It installs latest Ansible 2.2.2, that is.

pip + ansible modules is a different issue. We've never ran anything with custom Ansible modules yet.
I replied in #5 to help with further debugging.

@armab

This comment has been minimized.

Copy link
Member

armab commented Apr 24, 2018

Just got an idea. We could go with the following approach:

Create branches in this repo for respective Ansible versions: 2.2, 2.3, 2.4, 2.5, pinning Ansible version in pip requirements.

And so pack install for Ansible 2.2 will look this way:

st2 pack install ansible=2.2

because pack install can take any git endpoint (tag, sha, branch) https://docs.stackstorm.com/packs.html#installing-a-pack

Two downsides:

  • This might be confusing with pack versions. Ex: st2 pack install ansible=v0.5.3 to install Ansible pack v0.5.3 git tag (pack version) vs st2 pack install ansible=2.2 to install Ansible pack from 2.2 git branch.
  • Cherry-pick fixes/changes from master to older branches might took a lot of time, considering increasing Ansible releases

@cognifloyd @nmaludy @brainstorm WDYT?

@nmaludy

This comment has been minimized.

Copy link
Contributor

nmaludy commented Apr 24, 2018

@armab i really like the idea! we could potentially tag it with something like ansible-v2.5 to be a little less ambiguous from the release version.

So i guess on the CLI it would look like:

st2 pack install ansible=ansible-v2.5

Then to install a specific pack version it would be:

st2 pack install ansible=v0.1.2
@cognifloyd

This comment has been minimized.

Copy link
Contributor

cognifloyd commented Apr 27, 2018

I like ansible-v2.5 being a branch.

Is there any way for this pack to hook into CI to add some additional tasks? It would be fairly simple to have a single commit that changes the ansible version in that branch, and then every time we tag a new version on the master branch, the CI rebases the ansible-v* branches on top of the master branch. A one line diff on requirements should be fairly resilient.

@LindsayHill

This comment has been minimized.

Copy link
Contributor

LindsayHill commented Apr 27, 2018

You can see the CI tasks in https://github.com/StackStorm-Exchange/stackstorm-ansible/blob/master/circle.yml

The deployment step there includes git tagging based upon version number in pack.yaml. If you like, you could add additional tasks in there. Currently that CircleCI config is the same as for all other Exchange packs, but it doesn't need to stay that way.

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