StackStorm / st2chatops

Packaging environment for building StackStorm chatops native packages
Apache License 2.0
32 stars 42 forks source link

OSError when executing ansible playbook from chatops #98

Closed bsmeding closed 5 years ago

bsmeding commented 6 years ago

When I create a new chatop action and alias to run a playbook, the playbook executes but thrown an error when executed from st2/chatops.

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: OSError: [Errno 2] No such file or directory
fatal: [hq-r1]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}
    to retry, use: --limit @/opt/stackstorm/packs/st2_chatops_aliases/playbooks/show_bgp_status.retry

when i execute the playbook manually it runs fine and output the bgp-neighbor.

I cannot find anything that is responsible for the error 'OSError' not on Ansible and not on ST2

bsmeding commented 6 years ago

I looks like ther is something wrong with virtualenv.

when i run locally wit virtualenv enabled it works,

(ansible) bsmeding@ansible-tools:/opt$ /opt/stackstorm/virtualenvs/ansible/bin/ansible-playbook /etc/ansible/playbooks/show_bgp_status.yaml --extra-vars='hosts=hq-r1'
 [WARNING]: Found variable using reserved name: hosts

PLAY [Check BGP status on hosts] *************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************************************************************
ok: [hq-r1]

TASK [Get BGP summ] **************************************************************************************************************************************************************************************************************************************************************************
ok: [hq-r1]

TASK [debug] *********************************************************************************************************************************************************************************************************************************************************************************
ok: [hq-r1] => {
    "msg": {
        "changed": false, 
        "failed": false, 
        "stdout": [
            "BGP router identifier 10.199.10.1, local AS number 1\nBGP table version is 7, main routing table version 7\n6 network entries using 840 bytes of memory\n6 path entries using 456 bytes of memory\n4/4 BGP path/bestpath attribute entries using 544 bytes of memory\n0 BGP route-map cache entries using 0 bytes of memory\n0 BGP filter-list cache entries using 0 bytes of memory\nBGP using 1840 total bytes of memory\nBGP activity 6/0 prefixes, 6/0 paths, scan interval 60 secs\n\nNeighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd\n1.1.1.18        4            2       0       0        1    0    0 never    Active\n1.1.1.19        4            3       0       0        1    0    0 never    Idle\n10.199.10.3     4            1       8      12        7    0    0 00:05:13        0"
        ], 
        "stdout_lines": [
            [
                "BGP router identifier 10.199.10.1, local AS number 1", 
                "BGP table version is 7, main routing table version 7", 
                "6 network entries using 840 bytes of memory", 
                "6 path entries using 456 bytes of memory", 
                "4/4 BGP path/bestpath attribute entries using 544 bytes of memory", 
                "0 BGP route-map cache entries using 0 bytes of memory", 
                "0 BGP filter-list cache entries using 0 bytes of memory", 
                "BGP using 1840 total bytes of memory", 
                "BGP activity 6/0 prefixes, 6/0 paths, scan interval 60 secs", 
                "", 
                "Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd", 
                "1.1.1.18        4            2       0       0        1    0    0 never    Active", 
                "1.1.1.19        4            3       0       0        1    0    0 never    Idle", 
                "10.199.10.3     4            1       8      12        7    0    0 00:05:13        0"
            ]
        ]
    }
}

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************************************************************
hq-r1                      : ok=3    changed=0    unreachable=0    failed=0   

(ansible) bsmeding@ansible-tools:/opt$ deactivate

but when disabled i get the same error. This wile ansible is NOT locally installed on the ST2 server

bsmeding@ansible-tools:/opt$ /opt/stackstorm/virtualenvs/ansible/bin/ansible-playbook /etc/ansible/playbooks/show_bgp_status.yaml --extra-vars='hosts=hq-r1'
 [WARNING]: Found variable using reserved name: hosts

PLAY [Check BGP status on hosts] *************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************************************************************
ok: [hq-r1]

TASK [Get BGP summ] **************************************************************************************************************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: OSError: [Errno 2] No such file or directory
fatal: [hq-r1]: FAILED! => {"failed": true, "msg": "Unexpected failure during module execution.", "stdout": ""}
 [WARNING]: Could not create retry file '/etc/ansible/playbooks/show_bgp_status.retry'.         [Errno 13] Permission denied: u'/etc/ansible/playbooks/show_bgp_status.retry'

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************************************************************
hq-r1                      : ok=1    changed=0    unreachable=0    failed=1   

how can i check the virtualenv in ST2 is correct loaded when executing the playbook?

LindsayHill commented 6 years ago

What does your alias look like? Which action is it calling? Is that action in the ansible pack, or another pack?