TripleO common AnsibleAction class fails on any add hoc command not formated ad dict

Bug #1805342 reported by Radoslaw Smigielski
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
tripleo
Fix Released
High
Radoslaw Smigielski

Bug Description

tripleo_common/actions/ansible.py AnsibleAction class provides a wrapper around ansible executable (not ansible-playbook). Normal ansible command allows to execute add hoc commands like below:

> ansible overcloud-Controller-2 --module-name shell --args "hostname"
> ansible overcloud-Controller-2 --args "hostname"

This is fully working but when remote command is going to have any param/switch this fails, example:

> ansible overcloud-Controller-2 --module-name shell --args "hostname -s"

The problem is that in AnsibleAction class --args is always treated as JSON and converted to string with json.dumps():

        self.module_args = self._kwargs_for_run.pop('module_args', None)
        if self.module_args:
            self.module_args = json.dumps(self.module_args)

so in my above example this is what we end up with:

(Pdb) command
['ansible', 'overcloud-Controller-2', '-vvvvv', '--module-name', 'shell', '--args', '"hostname -s"']
(Pdb) self.module_args
'"hostname -s"'

Changed in tripleo:
assignee: nobody → Radoslaw Smigielski (radoslaw-smigielski)
status: New → In Progress
summary: - TripleO common AnsibleAction class fails on any add hoccommand not
+ TripleO common AnsibleAction class fails on any add hoc command not
formated ad dict
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to tripleo-common (master)

Fix proposed to branch: master
Review: https://review.openstack.org/620236

description: updated
Changed in tripleo:
importance: Undecided → High
milestone: none → stein-2
tags: added: rocky-backport-potential
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to tripleo-common (master)

Reviewed: https://review.openstack.org/620236
Committed: https://git.openstack.org/cgit/openstack/tripleo-common/commit/?id=01fb1895a29a6f114045bef231feb6160b65ba80
Submitter: Zuul
Branch: master

commit 01fb1895a29a6f114045bef231feb6160b65ba80
Author: Radoslaw Smigielski <email address hidden>
Date: Tue Nov 27 08:21:34 2018 +0100

    Fix AnsibleAction.run() when argument is not a dict

    Fix ad hoc commands executed by AnsibleAction.run() when command is not
    passed as a dict() but as a normal string, the same way like ordinary
    ansible command works.
    Check if argument is a dict() and only if it is, use json.dumps() on it.
    And not break commands passed as string.

    Change-Id: I8b18658bfbae57f264db007e5e81556b0512ef55
    Closes-bug: 1805342

Changed in tripleo:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to tripleo-common (stable/rocky)

Fix proposed to branch: stable/rocky
Review: https://review.openstack.org/628111

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to tripleo-common (stable/queens)

Fix proposed to branch: stable/queens
Review: https://review.openstack.org/628112

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to tripleo-common (stable/rocky)

Reviewed: https://review.openstack.org/628111
Committed: https://git.openstack.org/cgit/openstack/tripleo-common/commit/?id=0af9f9942e343c7cf5efce52a6859cb2d605bec0
Submitter: Zuul
Branch: stable/rocky

commit 0af9f9942e343c7cf5efce52a6859cb2d605bec0
Author: Radoslaw Smigielski <email address hidden>
Date: Tue Nov 27 08:21:34 2018 +0100

    Fix AnsibleAction.run() when argument is not a dict

    Fix ad hoc commands executed by AnsibleAction.run() when command is not
    passed as a dict() but as a normal string, the same way like ordinary
    ansible command works.
    Check if argument is a dict() and only if it is, use json.dumps() on it.
    And not break commands passed as string.

    Change-Id: I8b18658bfbae57f264db007e5e81556b0512ef55
    Closes-bug: 1805342
    (cherry picked from commit 01fb1895a29a6f114045bef231feb6160b65ba80)

tags: added: in-stable-rocky
tags: added: in-stable-queens
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to tripleo-common (stable/queens)

Reviewed: https://review.openstack.org/628112
Committed: https://git.openstack.org/cgit/openstack/tripleo-common/commit/?id=8b99bba4dedf526a0b7f7917e25a5d2a8cbdfa9c
Submitter: Zuul
Branch: stable/queens

commit 8b99bba4dedf526a0b7f7917e25a5d2a8cbdfa9c
Author: Radoslaw Smigielski <email address hidden>
Date: Tue Nov 27 08:21:34 2018 +0100

    Fix AnsibleAction.run() when argument is not a dict

    Fix ad hoc commands executed by AnsibleAction.run() when command is not
    passed as a dict() but as a normal string, the same way like ordinary
    ansible command works.
    Check if argument is a dict() and only if it is, use json.dumps() on it.
    And not break commands passed as string.

    Change-Id: I8b18658bfbae57f264db007e5e81556b0512ef55
    Closes-bug: 1805342
    (cherry picked from commit 01fb1895a29a6f114045bef231feb6160b65ba80)

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/tripleo-common 10.3.0

This issue was fixed in the openstack/tripleo-common 10.3.0 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/tripleo-common 8.6.7

This issue was fixed in the openstack/tripleo-common 8.6.7 release.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/tripleo-common 9.5.0

This issue was fixed in the openstack/tripleo-common 9.5.0 release.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.