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

Cherry pick Tower credential fixes to stable-2.4 #36807

Merged
merged 9 commits into from
Mar 1, 2018

Conversation

samdoran
Copy link
Contributor

@samdoran samdoran commented Feb 28, 2018

SUMMARY

Cherry pick #36587, #36662, #36908, and #36917 into stable-2.4.

There were multiple merge conflicts that I resolved by hand. This needs to be approved by @ryanpetrello and/or @wenottingham before it is ok to merge.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

tower_credential.py

ANSIBLE VERSION
2.4

@ansibot
Copy link
Contributor

ansibot commented Feb 28, 2018

The test ansible-test compile --python 2.6 [?] failed with the following error:

lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:275:5: SyntaxError: )

The test ansible-test compile --python 2.7 [?] failed with the following error:

lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:275:5: SyntaxError: )

The test ansible-test compile --python 3.5 [?] failed with the following error:

lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:275:5: SyntaxError: )

The test ansible-test compile --python 3.6 [?] failed with the following error:

lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:275:5: SyntaxError: )

The test ansible-test sanity --test ansible-doc --python 2.6 [?] failed with the following error:

Command "ansible-doc tower_credential" returned exit status 1.
>>> Standard Error
ERROR! module tower_credential missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test ansible-doc --python 3.5 [?] failed with the following error:

Command "ansible-doc tower_credential" returned exit status 1.
>>> Standard Error
ERROR! module tower_credential missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test ansible-doc --python 2.7 [?] failed with the following error:

Command "ansible-doc tower_credential" returned exit status 1.
>>> Standard Error
ERROR! module tower_credential missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test ansible-doc --python 3.6 [?] failed with the following error:

Command "ansible-doc tower_credential" returned exit status 1.
>>> Standard Error
ERROR! module tower_credential missing documentation (or could not parse documentation): Parsing produced an empty object.

The test ansible-test sanity --test import --python 2.6 [?] failed with the following error:

lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:275:5: SyntaxError: invalid syntax

The test ansible-test sanity --test import --python 2.7 [?] failed with the following error:

lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:275:5: SyntaxError: invalid syntax

The test ansible-test sanity --test import --python 3.5 [?] failed with the following error:

lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:275:5: SyntaxError: invalid syntax

The test ansible-test sanity --test import --python 3.6 [?] failed with the following error:

lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:275:5: SyntaxError: invalid syntax

The test ansible-test sanity --test pep8 [?] failed with the following errors:

lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:277:5: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:278:29: E225 missing whitespace around operator
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:280:5: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:280:9: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:280:11: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:281:5: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:281:17: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:281:19: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:282:5: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:282:10: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:282:12: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:284:5: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:284:16: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:284:18: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:286:5: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:286:15: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:286:17: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:287:5: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:289:19: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:289:21: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:291:19: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:291:21: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:292:40: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:292:42: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:293:27: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:293:29: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:296:24: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:296:26: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:297:20: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:297:22: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:297:39: E225 missing whitespace around operator
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:298:39: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:298:41: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:306:31: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:306:33: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:308:32: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:308:34: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:309:42: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:309:44: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:312:38: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:312:40: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:315:25: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:315:27: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:316:21: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:316:23: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:316:45: E225 missing whitespace around operator
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:317:31: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:317:33: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:320:25: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:320:27: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:321:21: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:321:23: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:321:41: E225 missing whitespace around operator
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:322:31: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:322:33: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:324:29: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:324:31: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:326:25: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:326:27: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:328:41: E225 missing whitespace around operator
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:330:41: E225 missing whitespace around operator
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:332:53: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:332:55: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:335:25: E113 unexpected indentation
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:339:17: E128 continuation line under-indented for visual indent
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:340:21: E128 continuation line under-indented for visual indent
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:340:42: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:340:44: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:342:13: E128 continuation line under-indented for visual indent
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:343:17: E128 continuation line under-indented for visual indent
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:343:23: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:343:25: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:344:17: E128 continuation line under-indented for visual indent
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:344:34: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:344:36: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:345:13: E128 continuation line under-indented for visual indent
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:346:17: E128 continuation line under-indented for visual indent
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:346:23: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:346:25: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:347:9: E128 continuation line under-indented for visual indent
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:348:33: E225 missing whitespace around operator
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:348:117: E225 missing whitespace around operator
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:349:9: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:350:33: E225 missing whitespace around operator
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:350:93: E225 missing whitespace around operator
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:352:5: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:352:27: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:352:29: E251 unexpected spaces around keyword / parameter equals
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:353:5: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:356:1: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:357:1: E122 continuation line missing indentation or outdented
lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:359:1: E901 TokenError: EOF in multi-line statement

The test ansible-test sanity --test pylint [?] failed with the following error:

lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:275:0: syntax-error invalid syntax (<string>, line 275)

The test ansible-test sanity --test validate-modules [?] failed with the following error:

lib/ansible/modules/web_infrastructure/ansible_tower/tower_credential.py:0:0: E401 Python SyntaxError while parsing module

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Feb 28, 2018

@ansibot ansibot added WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. affects_2.4 This issue/PR affects Ansible v2.4 backport This PR does not target the devel branch. bugfix_pull_request module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Feb 28, 2018
@samdoran
Copy link
Contributor Author

Ooof. Apparently I butchered that.

@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Feb 28, 2018
@samdoran
Copy link
Contributor Author

samdoran commented Mar 1, 2018

@ryanpetrello Can you take a look at this and make sure it's ok?

except ImportError:
HAS_TOWER_CLI = False
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is right, because I don't think that ansible.module_utils.ansible_tower.HAS_TOWER_CLI exists in stable-2.4

It looks to me like you need a mix of the two, something like this:

+import os
+
+from ansible.module_utils.ansible_tower import tower_argument_spec, tower_auth_config, tower_check_mode
+
 try:
-    import os		
      import tower_cli
      import tower_cli.utils.exceptions as exc
  		  
      from tower_cli.conf import settings
-    from ansible.module_utils.ansible_tower import tower_auth_config, tower_check_mode		
-		
     HAS_TOWER_CLI = True
  except ImportError:
     HAS_TOWER_CLI = False

@ryanpetrello
Copy link
Contributor

ryanpetrello commented Mar 1, 2018

Hey @samdoran, thank you for working on this. I'm going to pull this down and test it today.

@ansibot ansibot added the bug This issue/PR relates to a bug. label Mar 1, 2018
@ryanpetrello
Copy link
Contributor

@wwitzel3 @AlanCoding would you two also give this some careful scrutiny and let me know if you see any issues?

@ryanpetrello
Copy link
Contributor

ryanpetrello commented Mar 1, 2018

@samdoran I think I'm going to have to introduce one more minor change to devel, and we'll need it here as well:

#36908

@samdoran samdoran added this to Blocker in 2.4.x Blocker List Mar 1, 2018
@ryanpetrello
Copy link
Contributor

ryanpetrello commented Mar 1, 2018

@samdoran this looks correct to me:

$ cat make_cred.yml
- hosts: all
  tasks:
  - tower_credential:
      name: FINAL TEST
      organization: Default
      state: present
      kind: ssh
      username: ryan
      password: secret
      ssh_key_data: "~/.ssh/id_rsa"
      ssh_key_unlock: foo
      tower_config_file: "test.cfg"
$ pip install git+https://github.com/samdoran/ansible.git@cherry-pick/2.4/36587
$ pip install git+https://github.com/ansible/tower-cli.git
$ tower-cli --version
Tower CLI 3.2.1
$ PYTHONPATH=$VIRTUAL_ENV/lib/python2.7/site-packages ansible-playbook -i localhost, -c local make_cred.yml -v
Using /etc/ansible/ansible.cfg as config file

PLAY [all] ***********************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
ok: [localhost]

TASK [tower_credential] **********************************************************************************************************************************************************************************************************************
changed: [localhost] => {"changed": true, "credential": "FINAL TEST", "failed": false, "id": 7, "state": "present"}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0

Note that the username, password, SSH key, and keypass are all set:
screen shot 2018-03-01 at 3 35 13 pm

Also works against a Tower 3.1.5 install:

# Run against a Tower 3.1.5 host
$ pip install git+https://github.com/samdoran/ansible.git@cherry-pick/2.4/36587
$ pip install git+https://github.com/ansible/tower-cli.git@v3.1.8
$ tower-cli --version
Tower CLI 3.1.8
$ PYTHONPATH=$VIRTUAL_ENV/lib/python2.7/site-packages ansible-playbook -i localhost, -c local make_cred.yml -v
Using /etc/ansible/ansible.cfg as config file

PLAY [all] ***********************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************
ok: [localhost]

TASK [tower_credential] **********************************************************************************************
changed: [localhost] => {"changed": true, "credential": "FINAL TEST", "failed": false, "id": 6, "state": "present"}

PLAY RECAP ***********************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0

screen shot 2018-03-01 at 3 37 34 pm

@AlanCoding would you mind double checking my work here?

@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Mar 1, 2018
@ansibot
Copy link
Contributor

ansibot commented Mar 1, 2018

ryanpetrello and others added 6 commits March 1, 2018 20:40
(cherry picked from commit 640749d)
…nsible#36662)

older versions of Tower (3.1) don't have a concept of CredentialTypes
(this was introduced in Tower 3.2).  This change detects older versions
of pre-3.2 tower-cli that *only* support the deprecated `kind`
attribute.

(cherry picked from commit 641f8b4)
@ansibot ansibot removed the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Mar 1, 2018
@samdoran samdoran changed the title [WIP] Cherry pick 36587 and 36662 to stable-2.4 Cherry pick Tower credential fixes to stable-2.4 Mar 1, 2018
@AlanCoding
Copy link
Member

shipit

@ryanpetrello
Copy link
Contributor

:shipit: indeed

@samdoran samdoran removed the WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. label Mar 1, 2018
@samdoran samdoran merged commit 47eccd3 into ansible:stable-2.4 Mar 1, 2018
@samdoran samdoran deleted the cherry-pick/2.4/36587 branch March 1, 2018 20:54
@samdoran samdoran moved this from Blocker to Done in 2.4.4 in 2.4.x Blocker List Mar 1, 2018
@dagwieers dagwieers added the tower Tower community label Feb 8, 2019
@ansible ansible locked and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.4 This issue/PR affects Ansible v2.4 backport This PR does not target the devel branch. bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. tower Tower community
Projects
No open projects
2.4.x Blocker List
Done in 2.4.4
Development

Successfully merging this pull request may close these issues.

None yet

6 participants