apenella / go-ansible

Go-ansible is a Go package that enables the execution of ansible-playbook or ansible commands directly from Golang applications. It supports a wide range of options for each command, enabling smooth integration of Ansible functionality into your projects.
MIT License
875 stars 142 forks source link

There is an error in this type(AnsiblePlaybookJSONResultsPlayTaskHostsItem.plays.tasks.hosts.unreachable) #106

Closed HCY2315 closed 2 years ago

HCY2315 commented 2 years ago

error info: json: cannot unmarshal bool into Go struct field AnsiblePlaybookJSONResultsPlayTaskHostsItem.plays.tasks.hosts.unreachable of type string: Error decoding results json: cannot unmarshal bool into Go struct field AnsiblePlaybookJSONResultsPlayTaskHostsItem.plays.tasks.hosts.unreachable of type string

{
    "custom_stats": {},
    "global_custom_stats": {},
    "plays": [
        {
            "play": {
                "duration": {
                    "end": "2022-07-20T03:32:12.305270Z",
                    "start": "2022-07-20T03:32:02.222928Z"
                },
                "id": "acde4800-1122-da97-76a8-00000000000a",
                "name": "192.168.31.230,2.2.2.2"
            },
            "tasks": [
                {
                    "hosts": {
                        "192.168.31.230": {
                            "_ansible_no_log": false,
                            "action": "shell",
                            "failed": true,
                            "msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."
                        },
                        "2.2.2.2": {
                            "action": "shell",
                            "changed": false,
                            "msg": "Failed to connect to the host via ssh: ssh: connect to host 2.2.2.2 port 22: Operation timed out",
                            "unreachable": true
                        }
                    },
                    "task": {
                        "duration": {
                            "end": "2022-07-20T03:32:12.305270Z",
                            "start": "2022-07-20T03:32:02.242328Z"
                        },
                        "id": "acde4800-1122-da97-76a8-00000000000c",
                        "name": "preAction"
                    }
                }
            ]
        }
    ],
    "stats": {
        "192.168.31.230": {
            "changed": 0,
            "failures": 1,
            "ignored": 0,
            "ok": 0,
            "rescued": 0,
            "skipped": 0,
            "unreachable": 0
        },
        "2.2.2.2": {
            "changed": 0,
            "failures": 0,
            "ignored": 0,
            "ok": 0,
            "rescued": 0,
            "skipped": 0,
            "unreachable": 1
        }
    }
}

The unreachable field in the buff information I checked is of bool type

apenella commented 2 years ago

HI @HCY2315 It should be already been fixed on master branch. It doesn't belong to any release yet.

Could you use master branch instead of using the tag?

Here you have the fix: https://github.com/apenella/go-ansible/pull/103/files#diff-eafbef43147ddf52d1d65411fa7d41401688dfb40b5cfa0204ec675b30425d87R104

bytesizedwizard commented 2 years ago

Hi there, Any update on when this will be available in a release?

Also, thanks for this awesome package!

apenella commented 2 years ago

Hi @thedarthcoder I don't have an estimated time for the next release. Since https://github.com/apenella/go-ansible/pull/103 is the only fix ready to be released, I am going to wait at least a couple of months before releasing it with fixes.

Thank you very much!

apenella commented 2 years ago

@thedarthcoder @HCY2315 the fix is already available on the release v1.1.7.

I close the issue. Thanks!