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

Update Ansible doc #65

Merged
merged 11 commits into from
Mar 25, 2024
2 changes: 1 addition & 1 deletion docs/cnspec/cli/cnspec_scan.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ cnspec scan --inventory-file FILENAME
#### Scan an Ansible inventory file

```bash
ansible-inventory -i hosts.ini --list | cnspec scan --inventory-format-ansible --inventory-file FILENAME
ansible-inventory -i hosts.ini --list | cnspec scan --inventory-format-ansible
Copy link
Member

Choose a reason for hiding this comment

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

Piping in the file from ansible doesn't seem to work:

 ~/dev  ansible-inventory -i hosts.ini --list
{
    "_meta": {
        "hostvars": {}
    },
    "all": {
        "children": [
            "ungrouped",
            "servers"
        ]
    },
    "servers": {
        "hosts": [
            "172.16.1.50",
            "172.16.1.248"
        ]
    }
}
 ~/dev  ansible-inventory -i hosts.ini --list | cnspec scan --inventory-format-ansible
→ no provider specified, defaulting to local. Use --help to see all providers.
→ loaded configuration from /Users/tsmith/.config/mondoo/mondoo.yml using source default
→ using service account credentials
→ discover related assets for 1 asset(s)

 Tim-Smith.localdomain ────────────────────────────────────────────────────────────────────────────────────────────   0%

This scanned my local system

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And your shell does support piping?

Copy link
Member

Choose a reason for hiding this comment

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

yep

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay @tas50, to troubleshoot, does this scan your Ansible inventory?

ansible-inventory -i hosts.ini --list > hosts.json
cnspec scan --inventory-file hosts.json --inventory-format-ansible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reply to me was:

Auth fails, but it does in fact pick things up that way:

→ no provider specified, defaulting to local. Use --help to see all providers.
→ found a new version for 'os' provider installed=10.3.7 latest=10.4.0
→ successfully installed os provider path=/Users/tsmith/.config/mondoo/providers/os version=10.4.0
→ loaded configuration from /Users/tsmith/.config/mondoo/mondoo.yml using source default
→ load inventory inventory-file=hosts.json
→ use ansible inventory
→ using service account credentials
→ discover related assets for 2 asset(s)
! could not find keys in ssh agent
x unable to create runtime for asset error="rpc error: code = Unknown desc = no authentication method defined" asset=172.16.1.50
! could not find keys in ssh agent
x unable to create runtime for asset error="rpc error: code = Unknown desc = no authentication method defined" asset=172.16.1.248
Asset: 172.16.1.248
-------------------

error: rpc error: code = Unknown desc = no authentication method defined


Scanned 1 asset

tas50 marked this conversation as resolved.
Show resolved Hide resolved
```

### Options
Expand Down
2 changes: 1 addition & 1 deletion docs/platform/infra/opsys/automation/ansible.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ The method for scanning an Ansible inventory depends on whether your shell suppo
The first option if you are using a shell such as `bash` or `zsh` that supports `|` redirects is to pipe the output of the `ansible-inventory -i hosts.ini --list` command to `cnspec scan --inventory-format-ansible`. For `FILENAME`, substitute the name of the inventory file.

```bash title="Pipe the contents of an Ansible inventory to the cnspec scan command"
ansible-inventory -i hosts.ini --list | cnspec scan --inventory-format-ansible --inventory-file FILENAME --insecure
ansible-inventory -i hosts.ini --list | cnspec scan --inventory-format-ansible --insecure
```

:::info
Expand Down
Loading