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

Synchronize: suppress synchronize verbose output #220

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

mandar242
Copy link
Contributor

SUMMARY

Adding rsync 'quiet' option to synchronize module.
Allows to suppress synchronize verbose output.

Resolves #171

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

Synchronize

@mandar242 mandar242 changed the title Issues/171/suppress synchronize verbose output Synchronize: suppress synchronize verbose output Jul 12, 2021
Copy link
Member

@gravesm gravesm left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @mandar242!

plugins/modules/synchronize.py Outdated Show resolved Hide resolved
plugins/modules/synchronize.py Outdated Show resolved Hide resolved
@gravesm
Copy link
Member

gravesm commented Jul 12, 2021

@mandar242
Copy link
Contributor Author

Could you also add a changelog fragment: https://docs.ansible.com/ansible/latest/community/development_process.html#community-changelogs?

Added.

Copy link
Member

@Akasurde Akasurde left a comment

Choose a reason for hiding this comment

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

Small nit-picks. Could you please add tests for this change? Thanks.

changelogs/fragments/220_synchronize_add_quiet_option.yml Outdated Show resolved Hide resolved
plugins/modules/synchronize.py Outdated Show resolved Hide resolved
plugins/modules/synchronize.py Outdated Show resolved Hide resolved
@Akasurde Akasurde force-pushed the issues/171/suppress-synchronize-verbose-output branch from 8cdd122 to 39930ca Compare July 14, 2021 04:10
@Akasurde
Copy link
Member

cc @quidame @saito-hideki Could you please review this? Thanks in advance.

saito-hideki
saito-hideki previously approved these changes Jul 14, 2021
Copy link
Collaborator

@saito-hideki saito-hideki left a comment

Choose a reason for hiding this comment

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

Hi! thank you for sending the PR!
Currently, we need to append --allow-disabled to perform the integration tests, but this PR and the integration tests worked fine in my testing environment.
BTW, a fix for the aliases file to enable the integration tests has been already included in another PR #213. So this PR looks reasonable to me even if it does not include the aliases file changing :)

@gravesm
Copy link
Member

gravesm commented Jul 14, 2021

This change actually may not work as is. It's breaking the ability to determine changed status. Testing locally for me shows no change when there is, in fact, a change. I think I'm not sure what extraneous output the OP was referring to is. The only case I can find where -v is being used is when link_dest is set, and the note in the code seems to suggest this is required here. @phemmer can you clarify what output you are referring to and possibly provide an example task to reproduce?

@mandar242 pending further information about what's being requested in this feature, we should add a few more tests to this. At least one to check that a task's result has changed and then a following one running the same task to check that the result has not changed.

@quidame
Copy link
Contributor

quidame commented Jul 14, 2021

as reported by @gravesm , adding --quiet option just breaks check_mode. As said in rsync(1) manpage:

-q, --quiet                 suppress non-error messages

The check_mode and diff are based on --out-format option (with a marker in), which is suppressed by the use of --quiet.

Copy link
Collaborator

@saito-hideki saito-hideki left a comment

Choose a reason for hiding this comment

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

Sorry guys, I missed the point pointed out by @gravesm and @quidame. I'll revert my approval and wait for updates

@phemmer
Copy link

phemmer commented Jul 22, 2021

@phemmer can you clarify what output you are referring to and possibly provide an example task to reproduce?

$ mkdir /tmp/a

$ touch /tmp/a/{1..100}

$ ansible localhost -m synchronize -a 'src=/tmp/a/ dest=/tmp/b/'
[WARNING]: No inventory was parsed, only implicit localhost is available
localhost | CHANGED => {
    "changed": true,
    "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --out-format=<<CHANGED>>%i %n%L /tmp/a/ /tmp/b/",
    "msg": "cd+++++++++ ./\n>f+++++++++ 1\n>f+++++++++ 10\n>f+++++++++ 100\n>f+++++++++ 11\n>f+++++++++ 12\n>f+++++++++ 13\n>f+++++++++ 14\n>f+++++++++ 15\n>f+++++++++ 16\n>f+++++++++ 17\n>f+++++++++ 18\n>f+++++++++ 19\n>f+++++++++ 2\n>f+++++++++ 20\n>f+++++++++ 21\n>f+++++++++ 22\n>f+++++++++ 23\n>f+++++++++ 24\n>f+++++++++ 25\n>f+++++++++ 26\n>f+++++++++ 27\n>f+++++++++ 28\n>f+++++++++ 29\n>f+++++++++ 3\n>f+++++++++ 30\n>f+++++++++ 31\n>f+++++++++ 32\n>f+++++++++ 33\n>f+++++++++ 34\n>f+++++++++ 35\n>f+++++++++ 36\n>f+++++++++ 37\n>f+++++++++ 38\n>f+++++++++ 39\n>f+++++++++ 4\n>f+++++++++ 40\n>f+++++++++ 41\n>f+++++++++ 42\n>f+++++++++ 43\n>f+++++++++ 44\n>f+++++++++ 45\n>f+++++++++ 46\n>f+++++++++ 47\n>f+++++++++ 48\n>f+++++++++ 49\n>f+++++++++ 5\n>f+++++++++ 50\n>f+++++++++ 51\n>f+++++++++ 52\n>f+++++++++ 53\n>f+++++++++ 54\n>f+++++++++ 55\n>f+++++++++ 56\n>f+++++++++ 57\n>f+++++++++ 58\n>f+++++++++ 59\n>f+++++++++ 6\n>f+++++++++ 60\n>f+++++++++ 61\n>f+++++++++ 62\n>f+++++++++ 63\n>f+++++++++ 64\n>f+++++++++ 65\n>f+++++++++ 66\n>f+++++++++ 67\n>f+++++++++ 68\n>f+++++++++ 69\n>f+++++++++ 7\n>f+++++++++ 70\n>f+++++++++ 71\n>f+++++++++ 72\n>f+++++++++ 73\n>f+++++++++ 74\n>f+++++++++ 75\n>f+++++++++ 76\n>f+++++++++ 77\n>f+++++++++ 78\n>f+++++++++ 79\n>f+++++++++ 8\n>f+++++++++ 80\n>f+++++++++ 81\n>f+++++++++ 82\n>f+++++++++ 83\n>f+++++++++ 84\n>f+++++++++ 85\n>f+++++++++ 86\n>f+++++++++ 87\n>f+++++++++ 88\n>f+++++++++ 89\n>f+++++++++ 9\n>f+++++++++ 90\n>f+++++++++ 91\n>f+++++++++ 92\n>f+++++++++ 93\n>f+++++++++ 94\n>f+++++++++ 95\n>f+++++++++ 96\n>f+++++++++ 97\n>f+++++++++ 98\n>f+++++++++ 99\n",
    "rc": 0,
    "stdout_lines": [
        "cd+++++++++ ./",
        ">f+++++++++ 1",
        ">f+++++++++ 10",
        ">f+++++++++ 100",
        ">f+++++++++ 11",
        ">f+++++++++ 12",
        ">f+++++++++ 13",
...
        ">f+++++++++ 96",
        ">f+++++++++ 97",
        ">f+++++++++ 98",
        ">f+++++++++ 99"
    ]
}

^ The msg is the problem, as that's what ansible-playbook is going to display.

@quidame
Copy link
Contributor

quidame commented Jul 22, 2021

note that the --out-format option is given a marker (<<CHANGED>>), which is removed from the output before sending this output in the results (msg, stdout_lines). At this step (the module post-processing rsync results, and being aware of possible changes), I think it is doable to just keep rsync's stderr and suppress rsync's stdout if a user requests that with a quiet=true new module option :)

Maybe keep transfer metadata (number of files, duration...) anyway, even when hidding all the details, could be a good point.

@saito-hideki saito-hideki dismissed their stale review July 22, 2021 23:53

Reviewing this PR again based on the comments from other maintainers. In the meantime, revert my review status from approved to pending.

@quidame
Copy link
Contributor

quidame commented Jul 24, 2021

@mandar242 , I suggest you try with something like the following, which shouldn't break anything

@@ -619,14 +627,20 @@ def main():
     out_lines = out_clean.split('\n')
     while '' in out_lines:
         out_lines.remove('')
+
+    result = dict(changed=changed, rc=rc, cmd=cmdstr)
+
+    if quiet:
+        result['msg'] = "OUTPUT IS HIDDEN DUE TO 'quiet=true'"
+        result['stdout_lines'] = []
+    else:
+        result['msg'] = out_clean
+        result['stdout_lines'] = out_lines
+
     if module._diff:
-        diff = {'prepared': out_clean}
-        return module.exit_json(changed=changed, msg=out_clean,
-                                rc=rc, cmd=cmdstr, stdout_lines=out_lines,
-                                diff=diff)
+        result['diff'] = {'prepared': out_clean}
 
-    return module.exit_json(changed=changed, msg=out_clean,
-                            rc=rc, cmd=cmdstr, stdout_lines=out_lines)
+    return module.exit_json(**result)
 
 
 if __name__ == '__main__':

plugins/modules/synchronize.py Outdated Show resolved Hide resolved
plugins/modules/synchronize.py Outdated Show resolved Hide resolved
Copy link
Contributor

@quidame quidame left a comment

Choose a reason for hiding this comment

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

@mandar242 , please take care to not break the existing interface. In f508845 you changed the stdout_lines result into std_out, please don't do that.

plugins/modules/synchronize.py Outdated Show resolved Hide resolved
tests/integration/targets/synchronize/tasks/main.yml Outdated Show resolved Hide resolved
tests/integration/targets/synchronize/tasks/main.yml Outdated Show resolved Hide resolved
ignore_errors: true
- assert:
that:
- '''files/directories have been synchronized'' not in sync_result.msg'
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't really make sense for me: despite this assertion, we have no certainty that this string is not in the result msg when the synchronize module succeeds, because we have no certainty that the synchronize module has succeeded, from a logic point of view.

Unless one wants to trigger an error, for example to test error handling of the module and ensure it behaves correctly under stress or with bad parameter values - and in that case we also want the playbook to not fail if a given task fails as expected - please don't use ignore_errors=true. Never. This makes just the tests passing even if the module is broken, that is exactly what the tests are made to avoid. An example of consistent use of ignore_errors: https://github.com/ansible-collections/community.general/blob/main/tests/integration/targets/filesize/tasks/errors.yml

tests/integration/targets/synchronize/tasks/main.yml Outdated Show resolved Hide resolved
tests/integration/targets/synchronize/tasks/main.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@quidame quidame left a comment

Choose a reason for hiding this comment

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

LGTM

@phemmer
Copy link

phemmer commented Aug 8, 2023

2 years later, what's needed for this to be merged? I see there's a change requested to add tests, but it looks like tests are present.

@phemmer
Copy link

phemmer commented Aug 18, 2023

Ping? @Akasurde ?

@Akasurde
Copy link
Member

@phemmer sorry, but I am not actively looking into ansible.posix collection. @mandar242 Can you please rebase the branch and update version_added?

cc @saito-hideki @maxamillion Could you please take care of this PR? Thanks in advance.

@mandar242 mandar242 force-pushed the issues/171/suppress-synchronize-verbose-output branch from a072f0b to 92dc532 Compare August 22, 2023 19:07
@phemmer
Copy link

phemmer commented Nov 17, 2023

@saito-hideki @maxamillion

Hello???

@phemmer
Copy link

phemmer commented Jun 7, 2024

@cwchristerw
Copy link
Contributor

- This option specifies quiet option which on true suppresses the output.
type: bool
default: no
version_added: '1.3.0'
Copy link
Contributor

@cwchristerw cwchristerw Jun 7, 2024

Choose a reason for hiding this comment

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

Next minor version is 1.6.x. I think new features to modules would need to be in next minor release. Ps. I'm new to this, so I'm not sure 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

It's 1.6.0, not 1.6.x :) But yes, that will be the next minor version, and the next one that will get released. (The only question is when..)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added to 1.6.0

Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

I'm not sure that this option makes sense, since --quiet means "suppress non-error messages". But the module needs the output to determine whether something changed.

So IMO this feature breaks the module and should not be merged.

plugins/modules/synchronize.py Outdated Show resolved Hide resolved
plugins/modules/synchronize.py Outdated Show resolved Hide resolved
@felixfontein
Copy link
Contributor

It seems that the rebase 10 months ago reintroduced passing --quiet to rsync (the problem has been discussed and fixed before that rebase).

@phemmer
Copy link

phemmer commented Jun 7, 2024

@mandar242 since it has been years, if you no longer have the interest to maintain this PR, let me know and I can pick it up and open a new one.

@mandar242
Copy link
Contributor Author

@mandar242 since it has been years, if you no longer have the interest to maintain this PR, let me know and I can pick it up and open a new one.

@phemmer I am fine with either. But given the number of commits made over the time, I think it will be easier and quicker to open new PR with changes from this pr. Rebase could be complex.

@mandar242 mandar242 force-pushed the issues/171/suppress-synchronize-verbose-output branch from 92dc532 to 892c045 Compare June 7, 2024 21:46
@mandar242
Copy link
Contributor Author

@mandar242 since it has been years, if you no longer have the interest to maintain this PR, let me know and I can pick it up and open a new one.

@phemmer I am fine with either. But given the number of commits made over the time, I think it will be easier and quicker to open new PR with changes from this pr. Rebase could be complex.

@phemmer the PR has been rebased successfully. waiting for reviews
cc @maxamillion @saito-hideki @felixfontein

Copy link
Contributor

@@ -601,6 +614,9 @@ def main():

cmd.append(shlex_quote(source))
cmd.append(shlex_quote(dest))
if quiet:
cmd.append('--quiet')

Copy link

Choose a reason for hiding this comment

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

This break the change detection as @felixfontein was mentioning here

Plus we probably want to keep the changes in stdout_lines. It's only msg that we want to suppress them from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suppress syncronize verbose output
8 participants