ansible / lightbulb

Lightbulb has been deprecated and replaced by Ansible Workshops
https://ansible.github.io/workshops/
MIT License
480 stars 310 forks source link

modify .vimrc on control node to help view hidden characters #232

Open thisdwhitley opened 6 years ago

thisdwhitley commented 6 years ago

During workshops, a lot of time is spent troubleshooting YAML files. This might be easier if hidden characters are visible in vim. A .vimrc file is already being populated on the control node from lightbulb/tools/aws_lab_setup/roles/control_node/templates/vimrc.j2 which seems to be an appropriate place to add this..?

Also, there is nothing node-specific in this template, so should/could it use the file module to deploy instead of template?

thisdwhitley commented 6 years ago

This can be achieved by adding:

set listchars=eol:¬,tab:>␣,trail:~,extends:>,precedes:<,space:·

to lightbulb/tools/aws_lab_setup/roles/control_node/templates/vimrc.j2 and then instructing the users that they can view hidden characters by typing :set list in vim on their control node.

IPvSean commented 6 years ago

... .vimrc....

@dswhitley can you attach a screenshot or link to something so I can see what I am supposed to be seeing, I added this and didn't notice anything right away

Also, there is nothing node-specific in this template, so should/could it use the file module to deploy instead of template?

Yeah but we are already using templates, so we would need a files directory and if we ever did use a variable or jinja2 we would have to flip it back. I don't see an advantage right now in moving it around

thisdwhitley commented 6 years ago

I will see if I can show this better but in the meantime, did you execute the :set list (while editing a yml file) after modifying the .vimrc file?

I wonder if this is dependant on the version of vim..?

thisdwhitley commented 6 years ago

The special characters are easily modified (as specified in the .vimrc file), but here is a snippet of what it looks like as defined above:

-·name:·Create·EC2·security·group¬
··ec2_group:¬
····name:·insecure_all¬
····description:·all·ports·open¬
····region:·"{{·ec2_region·}}"¬
····vpc_id:·"{{·ec2_vpc_id·}}"¬
····rules:¬
······-·proto:·all¬
········cidr_ip:·0.0.0.0/0¬
····rules_egress:¬
······-·proto:·all¬
········cidr_ip:·0.0.0.0/0¬
··when:·ec2_exact_count·>=·1¬
··tags:¬
····-·always¬
····-·provision¬

My thought was that it would be configured on the control node, but not called out in the presentation. That way it wouldn't always be in the customers face, but if they ask for help troubleshooting their playbooks, we could inform them to "type :set list" in the file they're modifying so we can easily assist identifying misaligned blocks. They can turn this off by typing :set list! while editing a file with vim.

FULL DISCLOSURE: I had intended on proposing this change in a pull request but couldn't get to it immediately. I'm still figuring out the ideal workflow with git. In the future would it be preferable for me to make the change, create the pull request, and then have this sort of conversation in the pull request?

tima commented 6 years ago

Like the other ansible projects we use the gitflow workflow. Clone from lightbulb to your personal account (or rebase if you have one). Clone to your workspace. Create feature branch, make your changes, add/commit, push to your github repo then issue a PR to lightbulb from there.

Also, we now support nano now. Would be nice to see how we can implement something like this for those people.

thisdwhitley commented 6 years ago

The listchars setting I recommended above will not work with the version of vim installed on the control node (7.4.160). In fact, the hugely important space: item is not available to listchars until vim version 7.4.710. The latest version of vim available to RHEL7 is 7.4.160-2 so even that won't get us where we need to be.

As an alternative, I have considered modifying the spacehi vim plugin to highlight spaces at the beginning of a line, but realized that it would be no different than instructing students to enter /^ \+ within vim...

thisdwhitley commented 6 years ago

Also, we now support nano now. Would be nice to see how we can implement something like this for those people.

@tima inserting a character for whitespaces in nano can be accomplished by:

  1. Copying a .nanorc file to student's home directory consisting of: set whitespace "»·"
  2. Instructing student to "type Alt-P" while editing a file with nano (Alt is the default "Meta" key in nano but a student could have changed this...)

That will result in the following:

·name:·Create·EC2·security·group
··ec2_group:
····name:·insecure_all
····description:·all·ports·open
····region:·"{{·ec2_region·}}"
····vpc_id:·"{{·ec2_vpc_id·}}"
····rules:
······-·proto:·all
········cidr_ip:·0.0.0.0/0
····rules_egress:
······-·proto:·all
········cidr_ip:·0.0.0.0/0
··when:·ec2_exact_count·>=·1
··tags:
····-·always
····-·provision

I'm happy add this file as a template and update the Speaker Notes in ansible-essentials.html, but should I open a separate issue and then pull request for that? This issue is diverging a bit.

tima commented 6 years ago

@dswhitley If it's not too much trouble, why not submit a PR and we can discuss there? I don't think this issue is going to go any further without that.