Do not print the progress bar when running `snap` commands

I’m currenly working on an ansible module for managing snap packages. Ansible allows modules to return information, such as stdout of commands the module ran. I’d like to use this feature to provide users with snap command output, for example when installing a package, and I’d prefer this output to be tidy.

Right now the output looks like this:

"stdout_lines": [
        "",
        "[|] Stop snap \"duckmarines\" services\u001b[K",
        "[/] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
        "[-] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
        "[\\] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
        "[|] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
        "[/] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
        "[-] Remove security profile for snap \"duckmarines\" (11)\u001b[K",
        "\u001b[Kduckmarines removed"

As you can see, a new line is appended each time the spinner changes, and the output is littered with escape sequences.

I’d like it to look more like this instead:

"stdout_lines": [
        "",
        "Stop snap \"duckmarines\" services",
        "Remove security profile for snap \"duckmarines\"",
        "Remove security profile for snap \"duckmarines\"",
        "duckmarines removed"

I can of course filter it manually, but I think a “machine-friendly” output mode could be beneficial in a lot of other applications as well.

1 Like

I think the new ansimeter does this already. Could you try with 2.29?

Well, not quite. If you’re not on a terminal you get

$ snap install ohmygiraffe < /dev/null
ohmygiraffe 1.1.0a from 'popey' installed
$ snap remove ohmygiraffe < /dev/null
ohmygiraffe removed

which are just the notifications. If you really need the intermediate spinner messages that would be more work (not a lot, but a little).

WDYT?

I think I’ll just implement your solution for now, as finishing more important features of the module takes priority and I don’t have much time to work on it right now. Plus, the other messages are not that important (although they would probably be helpful to a user debugging his playbook).