I give my honest opinion almost all the time. It does definitely get you in trouble. It also can help you and help the organization a great deal. I have become more willing to not bother wasting my time with "power" that has no interest in actually improving things.
I am not interested in working in a place where we are not pushing toward evidence based management and seeking real situational awareness not avoidance and burying heads in the sand.
Related: The Lazy Unreasonable Man - The Importance of Management Improvement - Performance without Appraisal
One way I have always looked at it is you will be targeted if you speak up. So if you want to avoid that just be like most others and don't speak up. But if you can make things better by speaking up you will gain allies. This isn't perfect though and it counts on people being smart enough to notice that you are helping them even if occasionally you force them to look at things they would rather avoid.
At one time I could tell after a while that a boss of mine didn't really want to know how they could improve. So they asked me, I told them they didn't really want to know. They said, yes they did. So I told them. They then moved into a new job and told the new boss watch out for this John Hunter, he will be far too critical and not accept how things have to be done, he is a troublemaker.
The new boss called me in and talked to me about the kinds of problems that she saw and some reports of what I had been saying should be done. She asked me some more questions about what could be done to improve things. Then see decided to have me report directly to her 2 days a week to work on getting the organization to change. The organization obviously was failing and they needed change and the huge resistance to change was something she thought required people that were not going to just go along with what had been done and attempt to resist all change.
I took several lessons from this. One my judgement was right, trust what you see in the actions of a boss, not just their words. If you are mostly worried about protecting your job just say what you can tell your boss wants to hear. If however, you are willing to stand up for your beliefs and think you can provide good value you can take the risk and try and improve the organization.
Even if your boss tries to sabotage you it may not work. This is very risky - it was pretty unlikely the new boss would have been so open to new ideas. But she was brought in from the outside specifically because of the continued poor performance fostered by the culture of pretending everything is basically good and blaming employees for failures instead of improving the system... I have always felt free to take risks and if the boss didn't like it then I could look elsewhere. This isn't the best strategy if you are most concerned with keeping your job - it can easily create problems.