Nigel  Uys

Nigel Uys

1673456700

A Vim Plugin for Syntax Highlighting ansible's Common Filetypes

Introduction

This is a vim syntax plugin for Ansible 2.x, it supports YAML playbooks, Jinja2 templates, and Ansible's hosts files.

  • YAML playbooks are detected if:
    • they are in the group_vars or host_vars folder
    • they are in the tasks, roles, or handlers folder and have either a .yml or .yaml suffix
    • they are named playbook.y(a)ml, site.y(a)ml, or main.y(a)ml
  • Jinja2 templates are detected if they have a .j2 suffix
  • Files named hosts will be treated as Ansible hosts files

You can also set the filetype to yaml.ansible, *.jinja2, or ansible_hosts if auto-detection does not work (e.g. :set ft=yaml.ansible or :set ft=ruby.jinja2). Note: If you want to detect a custom pattern of your own, you can easily add this in your .vimrc using something like this:

au BufRead,BufNewFile */playbooks/*.yml set filetype=yaml.ansible

If you want to override the default file type detection you can easily do this in your .vimrc. For example if you use YAML syntax for hosts include something like this:

augroup ansible_vim_fthosts
  autocmd!
  autocmd BufNewFile,BufRead hosts setfiletype yaml.ansible
augroup END

This plugin should be quite reliable, as it sources the original formats and simply modifies the highlights as appropriate. This also enables a focus on simplicity and configurability instead of patching bad syntax detection.

examples (with solarized colorscheme)

Bright (and selective highlight)Dim

installation

Use your favorite plugin manager, or try vim-plug if you're looking for a really nice one!

vim-plug: Plug 'pearofducks/ansible-vim'

vim-plug with post-update hook: Plug 'pearofducks/ansible-vim', { 'do': './UltiSnips/generate.sh' }

Note: Because of Ansible API changes, generate.sh may require the latest (or near-latest) version of Ansible.

Note2: generate.sh can receive some parameters, for more info see its Readme

vundle: Plugin 'pearofducks/ansible-vim'

pathogen: git clone https://github.com/pearofducks/ansible-vim ~/.vim/bundle/ansible-vim

Arch Linux: Package vim-ansible is available in the community repository.

Fedora: The vim-ansible package is available in the default repository.

RHEL/CentOS: The vim-ansible package is available in the EPEL repository.

options

g:ansible_unindent_after_newline

let g:ansible_unindent_after_newline = 1

When this variable is set, indentation will completely reset (unindent to column 0) after two newlines in insert-mode. The normal behavior of YAML is to always keep the previous indentation, even across multiple newlines with no content.

g:ansible_yamlKeyName

let g:ansible_yamlKeyName = 'yamlKey'

This option exists to provide additional compatibility with stephpy/vim-yaml.

g:ansible_attribute_highlight

let g:ansible_attribute_highlight = "ob"

Ansible modules use a key=value format for specifying module-attributes in playbooks. This highlights those as specified. This highlight option is also used when highlighting key/value pairs in hosts files.

Available flags (bold are defaults):

  • a: highlight all instances of key=
  • o: highlight only instances of key= found on newlines
  • d: dim the instances of key= found
  • b: brighten the instances of key= found
  • n: turn this highlight off completely

g:ansible_name_highlight

let g:ansible_name_highlight = 'd'

Ansible modules commonly start with a name: key for self-documentation of playbooks. This option enables/changes highlight of this.

Available flags (this feature is off by default):

  • d: dim the instances of name: found
  • b: brighten the instances of name: found

g:ansible_extra_keywords_highlight

let g:ansible_extra_keywords_highlight = 1

Note: This option is enabled when set, and disabled when not set.

Highlight the following additional keywords: become become_exe become_flags become_method become_user become_pass prompt_l10n debugger always_run check_mode diff no_log args tags force_handlers vars vars_files vars_prompt delegate_facts delegate_to any_errors_fatal ignore_errors ignore_unreachable max_fail_percentage connection hosts port remote_user module_defaults environment fact_path gather_facts gather_subset gather_timeout async poll throttle timeout order run_once serial strategy.

By default we only highlight: include include_role include_tasks include_vars import_role import_playbook import_tasks when changed_when failed_when block rescue always notify listen register action local_action post_tasks pre_tasks tasks handlers roles collections and loop keywords with_.+, loop, loop_control, until, retries, delay.

g:ansible_extra_keywords_highlight_group

let g:ansible_extra_keywords_highlight_group = 'Statement'

Accepts any syntax group name from :help E669 - e.g. Comment, Constant, Identifier

Note: Defaults to 'Structure' when not set.

g:ansible_normal_keywords_highlight

let g:ansible_normal_keywords_highlight = 'Constant'

Accepts any syntax group name from :help E669 - e.g. Comment, Constant, Identifier

Note: Defaults to 'Statement' when not set.

This option change the highlight of the following common keywords: include include_role include_tasks include_vars import_role import_playbook import_tasks when changed_when failed_when block rescue always notify listen register action local_action post_tasks pre_tasks tasks handlers roles collections.

g:ansible_loop_keywords_highlight

let g:ansible_loop_keywords_highlight = 'Constant'

Accepts any syntax group-name from :help E669 - e.g. Comment, Constant, Identifier

Note: Defaults to 'Statement' when not set.

This option changes the highlight of all with_.+, loop, loop_control, until, retries and delay keywords.

g:ansible_template_syntaxes

let g:ansible_template_syntaxes = { '*.rb.j2': 'ruby' }

Accepts a dictionary in the form of 'regex-for-file': 'filetype'.

  • regex-for-file will receive the full filepath, so directory matching can be done.
  • filetype is the root filetype to be applied, jinja2 will be automatically appended

All files ending in *.j2 that aren't matched will simply get the jinja2 filetype.

g:ansible_ftdetect_filename_regex

let g:ansible_ftdetect_filename_regex = '\v(playbook|site|main|local|requirements)\.ya?ml$'

Accepts a regex string that is used to match the filename to determine if the file should use the Ansible filetype

Can be used to avoid clashes with other files that are named the same - e.g. main.yaml used in github workflows by removing main from the regex

goto role under cursor (similar to gf)

This behavior is not supported out of the box, but you can use this snippet in your vimrc.

You'll then be able to go to a role's definition with <leader>gr.

bugs, suggestions/requests, & contributions

bugs

It's unlikely that there will be bugs in highlighting that don't exist in the core format. Where appropriate these will be fixed in this plugin, but if the problem is with the original syntax we should probably focus on fixing that instead.

Indenting a full document - e.g with gg=G - will not be supported and is not a goal of this plugin (unless someone else develops it!). Please do not file a bug report on this.

suggestions/requests

Suggestions for improvements are welcome, pull-requests with completed features even more so. :)

Download Details:

Author: Pearofducks
Source Code: https://github.com/pearofducks/ansible-vim 
License: MIT license

#ansible #vim 

What is GEEK

Buddha Community

A Vim Plugin for Syntax Highlighting ansible's Common Filetypes
Nigel  Uys

Nigel Uys

1673456700

A Vim Plugin for Syntax Highlighting ansible's Common Filetypes

Introduction

This is a vim syntax plugin for Ansible 2.x, it supports YAML playbooks, Jinja2 templates, and Ansible's hosts files.

  • YAML playbooks are detected if:
    • they are in the group_vars or host_vars folder
    • they are in the tasks, roles, or handlers folder and have either a .yml or .yaml suffix
    • they are named playbook.y(a)ml, site.y(a)ml, or main.y(a)ml
  • Jinja2 templates are detected if they have a .j2 suffix
  • Files named hosts will be treated as Ansible hosts files

You can also set the filetype to yaml.ansible, *.jinja2, or ansible_hosts if auto-detection does not work (e.g. :set ft=yaml.ansible or :set ft=ruby.jinja2). Note: If you want to detect a custom pattern of your own, you can easily add this in your .vimrc using something like this:

au BufRead,BufNewFile */playbooks/*.yml set filetype=yaml.ansible

If you want to override the default file type detection you can easily do this in your .vimrc. For example if you use YAML syntax for hosts include something like this:

augroup ansible_vim_fthosts
  autocmd!
  autocmd BufNewFile,BufRead hosts setfiletype yaml.ansible
augroup END

This plugin should be quite reliable, as it sources the original formats and simply modifies the highlights as appropriate. This also enables a focus on simplicity and configurability instead of patching bad syntax detection.

examples (with solarized colorscheme)

Bright (and selective highlight)Dim

installation

Use your favorite plugin manager, or try vim-plug if you're looking for a really nice one!

vim-plug: Plug 'pearofducks/ansible-vim'

vim-plug with post-update hook: Plug 'pearofducks/ansible-vim', { 'do': './UltiSnips/generate.sh' }

Note: Because of Ansible API changes, generate.sh may require the latest (or near-latest) version of Ansible.

Note2: generate.sh can receive some parameters, for more info see its Readme

vundle: Plugin 'pearofducks/ansible-vim'

pathogen: git clone https://github.com/pearofducks/ansible-vim ~/.vim/bundle/ansible-vim

Arch Linux: Package vim-ansible is available in the community repository.

Fedora: The vim-ansible package is available in the default repository.

RHEL/CentOS: The vim-ansible package is available in the EPEL repository.

options

g:ansible_unindent_after_newline

let g:ansible_unindent_after_newline = 1

When this variable is set, indentation will completely reset (unindent to column 0) after two newlines in insert-mode. The normal behavior of YAML is to always keep the previous indentation, even across multiple newlines with no content.

g:ansible_yamlKeyName

let g:ansible_yamlKeyName = 'yamlKey'

This option exists to provide additional compatibility with stephpy/vim-yaml.

g:ansible_attribute_highlight

let g:ansible_attribute_highlight = "ob"

Ansible modules use a key=value format for specifying module-attributes in playbooks. This highlights those as specified. This highlight option is also used when highlighting key/value pairs in hosts files.

Available flags (bold are defaults):

  • a: highlight all instances of key=
  • o: highlight only instances of key= found on newlines
  • d: dim the instances of key= found
  • b: brighten the instances of key= found
  • n: turn this highlight off completely

g:ansible_name_highlight

let g:ansible_name_highlight = 'd'

Ansible modules commonly start with a name: key for self-documentation of playbooks. This option enables/changes highlight of this.

Available flags (this feature is off by default):

  • d: dim the instances of name: found
  • b: brighten the instances of name: found

g:ansible_extra_keywords_highlight

let g:ansible_extra_keywords_highlight = 1

Note: This option is enabled when set, and disabled when not set.

Highlight the following additional keywords: become become_exe become_flags become_method become_user become_pass prompt_l10n debugger always_run check_mode diff no_log args tags force_handlers vars vars_files vars_prompt delegate_facts delegate_to any_errors_fatal ignore_errors ignore_unreachable max_fail_percentage connection hosts port remote_user module_defaults environment fact_path gather_facts gather_subset gather_timeout async poll throttle timeout order run_once serial strategy.

By default we only highlight: include include_role include_tasks include_vars import_role import_playbook import_tasks when changed_when failed_when block rescue always notify listen register action local_action post_tasks pre_tasks tasks handlers roles collections and loop keywords with_.+, loop, loop_control, until, retries, delay.

g:ansible_extra_keywords_highlight_group

let g:ansible_extra_keywords_highlight_group = 'Statement'

Accepts any syntax group name from :help E669 - e.g. Comment, Constant, Identifier

Note: Defaults to 'Structure' when not set.

g:ansible_normal_keywords_highlight

let g:ansible_normal_keywords_highlight = 'Constant'

Accepts any syntax group name from :help E669 - e.g. Comment, Constant, Identifier

Note: Defaults to 'Statement' when not set.

This option change the highlight of the following common keywords: include include_role include_tasks include_vars import_role import_playbook import_tasks when changed_when failed_when block rescue always notify listen register action local_action post_tasks pre_tasks tasks handlers roles collections.

g:ansible_loop_keywords_highlight

let g:ansible_loop_keywords_highlight = 'Constant'

Accepts any syntax group-name from :help E669 - e.g. Comment, Constant, Identifier

Note: Defaults to 'Statement' when not set.

This option changes the highlight of all with_.+, loop, loop_control, until, retries and delay keywords.

g:ansible_template_syntaxes

let g:ansible_template_syntaxes = { '*.rb.j2': 'ruby' }

Accepts a dictionary in the form of 'regex-for-file': 'filetype'.

  • regex-for-file will receive the full filepath, so directory matching can be done.
  • filetype is the root filetype to be applied, jinja2 will be automatically appended

All files ending in *.j2 that aren't matched will simply get the jinja2 filetype.

g:ansible_ftdetect_filename_regex

let g:ansible_ftdetect_filename_regex = '\v(playbook|site|main|local|requirements)\.ya?ml$'

Accepts a regex string that is used to match the filename to determine if the file should use the Ansible filetype

Can be used to avoid clashes with other files that are named the same - e.g. main.yaml used in github workflows by removing main from the regex

goto role under cursor (similar to gf)

This behavior is not supported out of the box, but you can use this snippet in your vimrc.

You'll then be able to go to a role's definition with <leader>gr.

bugs, suggestions/requests, & contributions

bugs

It's unlikely that there will be bugs in highlighting that don't exist in the core format. Where appropriate these will be fixed in this plugin, but if the problem is with the original syntax we should probably focus on fixing that instead.

Indenting a full document - e.g with gg=G - will not be supported and is not a goal of this plugin (unless someone else develops it!). Please do not file a bug report on this.

suggestions/requests

Suggestions for improvements are welcome, pull-requests with completed features even more so. :)

Download Details:

Author: Pearofducks
Source Code: https://github.com/pearofducks/ansible-vim 
License: MIT license

#ansible #vim 

Awesome Ansible List

Awesome Ansible

A collaborative curated list of awesome Ansible resources, tools, Roles, tutorials and other related stuff.

Ansible is an open source toolkit, written in Python, it is used for configuration management, application deployment, continuous delivery, IT infrastructure automation and automation in general.

Official resources

Official resources by and for Ansible.

Community

Places where to chat with the Ansible community

Tutorials

Tutorials and courses to learn Ansible.

Books

Books about Ansible.

Videos

Video tutorials and Ansible training.

Tools

Tools for and using Ansible.

  • Ansible Tower - Ansible Tower by Red Hat helps you scale IT automation, manage complex deployments and speed productivity. Extend the power of Ansible to your entire team.
  • AWX - AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is the upstream project for Tower, a commercial derivative of AWX.
  • Ansible Lint - Checks Playbooks for best practices and behavior that could potentially be improved.
  • Ansible Later - Another best practice scanner. Checks Playbooks and Roles for best practices and behavior that could potentially be improved.
  • Ansible Doctor - Simple annotation like documentation generator for Ansible roles based on Jinja2 templates.
  • Ansible cmdb - Takes the output of Ansible's fact gathering and converts it into a static HTML page.
  • ARA - ARA Records Ansible playbooks and makes them easier to understand and troubleshoot with a reporting API, UI and CLI.
  • Mitogen for Ansible - Speed up Ansible substantially with Mitogen.
  • Molecule - Molecule aids in the development and testing of Ansible roles.
  • Packer Ansible Provisioner - This Provisioner can be used to automate VM Image creation via Packer with Ansible.
  • Excel Ansible Inventory - Turn any Excel Spreadsheet into an Ansible Inventory.
  • terraform.py - Ansible dynamic inventory script for parsing Terraform state files.
  • ansible-navigator - A text-based user interface (TUI) for Ansible.
  • squest - Self-service portal for Ansible Tower job templates.
  • ansible-bender - Tool which bends containers using Ansible playbooks and turns them into container images.
  • ansible-runner - A tool and python library that helps when interfacing with Ansible directly or as part of another system whether that be through a container image interface, as a standalone tool, or as a Python module that can be imported.
  • ansible-builder - Using Ansible content that depends on non-default dependencies can be tricky. Packages must be installed on each node, play nicely with other software installed on the host system, and be kept in sync.
  • kics - SAST Tool that scans your ansible infrastructure as code playbooks for security vulnverables, compliance issues and misconfigurations.
  • php-ansible Library - OOP-Wrapper for Ansible, making Ansible available in PHP.
  • TD4A - Design aid for building and testing jinja2 templates, combines data in yaml format with a jinja2 template and render the output.
  • Ansible Playbook Grapher - Command line tool to create a graph representing your Ansible playbook plays, tasks and roles.
  • ansible-doc-extractor - A tool that extracts documentation from Ansible modules in the HTML form.
  • Ansible Semaphore - Ansible Semaphore is a modern UI for Ansible.

Blog posts and opinions

Best practices and other opinions on Ansible.

German

Playbooks, Roles and Collections

Awesome production ready Playbooks, Roles and Collections to get you up and running.


Download Details:

Author: ansible-community
Source Code: https://github.com/ansible-community/awesome-ansible

License: CC0-1.0 license

#ansible 

How To Customize WordPress Plugins? (4 Easy Ways To Do)

This is image title
WordPress needs no introduction. It has been in the world for quite a long time. And up till now, it has given a tough fight to leading web development technology. The main reason behind its remarkable success is, it is highly customizable and also SEO-friendly. Other benefits include open-source technology, security, user-friendliness, and the thousands of free plugins it offers.

Talking of WordPress plugins, are a piece of software that enables you to add more features to the website. They are easy to integrate into your website and don’t hamper the performance of the site. WordPress, as a leading technology, has to offer many out-of-the-box plugins.

However, not always the WordPress would be able to meet your all needs. Hence you have to customize the WordPress plugin to provide you the functionality you wished. WordPress Plugins are easy to install and customize. You don’t have to build the solution from scratch and that’s one of the reasons why small and medium-sized businesses love it. It doesn’t need a hefty investment or the hiring of an in-house development team. You can use the core functionality of the plugin and expand it as your like.

In this blog, we would be talking in-depth about plugins and how to customize WordPress plugins to improve the functionality of your web applications.

What Is The Working Of The WordPress Plugins?

Developing your own plugin requires you to have some knowledge of the way they work. It ensures the better functioning of the customized plugins and avoids any mistakes that can hamper the experience on your site.

1. Hooks

Plugins operate primarily using hooks. As a hook attaches you to something, the same way a feature or functionality is hooked to your website. The piece of code interacts with the other components present on the website. There are two types of hooks: a. Action and b. Filter.

A. Action

If you want something to happen at a particular time, you need to use a WordPress “action” hook. With actions, you can add, change and improve the functionality of your plugin. It allows you to attach a new action that can be triggered by your users on the website.

There are several predefined actions available on WordPress, custom WordPress plugin development also allows you to develop your own action. This way you can make your plugin function as your want. It also allows you to set values for which the hook function. The add_ action function will then connect that function to a specific action.

B. Filters

They are the type of hooks that are accepted to a single variable or a series of variables. It sends them back after they have modified it. It allows you to change the content displayed to the user.

You can add the filter on your website with the apply_filter function, then you can define the filter under the function. To add a filter hook on the website, you have to add the $tag (the filter name) and $value (the filtered value or variable), this allows the hook to work. Also, you can add extra function values under $var.

Once you have made your filter, you can execute it with the add_filter function. This will activate your filter and would work when a specific function is triggered. You can also manipulate the variable and return it.

2. Shortcodes

Shortcodes are a good way to create and display the custom functionality of your website to visitors. They are client-side bits of code. They can be placed in the posts and pages like in the menu and widgets, etc.

There are many plugins that use shortcodes. By creating your very own shortcode, you too can customize the WordPress plugin. You can create your own shortcode with the add_shortcode function. The name of the shortcode that you use would be the first variable and the second variable would be the output of it when it is triggered. The output can be – attributes, content, and name.

3. Widgets

Other than the hooks and shortcodes, you can use the widgets to add functionality to the site. WordPress Widgets are a good way to create a widget by extending the WP_Widget class. They render a user-friendly experience, as they have an object-oriented design approach and the functions and values are stored in a single entity.

How To Customize WordPress Plugins?

There are various methods to customize the WordPress plugins. Depending on your need, and the degree of customization you wish to make in the plugin, choose the right option for you. Also, don’t forget to keep in mind that it requires a little bit of technical knowledge too. So find an expert WordPress plugin development company in case you lack the knowledge to do it by yourself.

1. Hire A Plugin Developer3
This is image title

One of the best ways to customize a WordPress plugin is by hiring a plugin developer. There are many plugin developers listed in the WordPress directory. You can contact them and collaborate with world-class WordPress developers. It is quite easy to find a WordPress plugin developer.

Since it is not much work and doesn’t pay well or for the long term a lot of developers would be unwilling to collaborate but, you will eventually find people.

2. Creating A Supporting Plugin

If you are looking for added functionality in an already existing plugin go for this option. It is a cheap way to meet your needs and creating a supporting plugin takes very little time as it has very limited needs. Furthermore, you can extend a plugin to a current feature set without altering its base code.

However, to do so, you have to hire a WordPress developer as it also requires some technical knowledge.

3. Use Custom Hooks

Use the WordPress hooks to integrate some other feature into an existing plugin. You can add an action or a filter as per your need and improve the functionality of the website.

If the plugin you want to customize has the hook, you don’t have to do much to customize it. You can write your own plugin that works with these hooks. This way you don’t have to build a WordPress plugin right from scratch. If the hook is not present in the plugin code, you can contact a WordPress developer or write the code yourself. It may take some time, but it works.

Once the hook is added, you just have to manually patch each one upon the release of the new plugin update.

4. Override Callbacks

The last way to customize WordPress plugins is by override callbacks. You can alter the core functionality of the WordPress plugin with this method. You can completely change the way it functions with your website. It is a way to completely transform the plugin. By adding your own custom callbacks, you can create the exact functionality you desire.

We suggest you go for a web developer proficient in WordPress as this requires a good amount of technical knowledge and the working of a plugin.

Read More

#customize wordpress plugins #how to customize plugins in wordpress #how to customize wordpress plugins #how to edit plugins in wordpress #how to edit wordpress plugins #wordpress plugin customization

Vincent Lab

Vincent Lab

1605176204

Why I Think You Should Learn Vim as a Developer

In this video, I’ll be showing you why I think it’s good to know Vim as a Developer.

#vim #vim editor #text editor #what is vim #speed,2x dev #vim for node.js

Ansible Vim: Vim Syntax Plugin for Ansible 2.0

introduction

This is a vim syntax plugin for Ansible 2.x, it supports YAML playbooks, Jinja2 templates, and Ansible's hosts files.

  • YAML playbooks are detected if:
    • they are in the group_vars or host_vars folder
    • they are in the tasks, roles, or handlers folder and have either a .yml or .yaml suffix
    • they are named playbook.y(a)ml, site.y(a)ml, or main.y(a)ml
  • Jinja2 templates are detected if they have a .j2 suffix
  • Files named hosts will be treated as Ansible hosts files

You can also set the filetype to yaml.ansible, *.jinja2, or ansible_hosts if auto-detection does not work (e.g. :set ft=yaml.ansible or :set ft=ruby.jinja2). Note: If you want to detect a custom pattern of your own, you can easily add this in your .vimrc using something like this:

au BufRead,BufNewFile */playbooks/*.yml set filetype=yaml.ansible

If you want to override the default file type detection you can easily do this in your .vimrc. For example if you use YAML syntax for hosts include something like this:

augroup ansible_vim_fthosts
  autocmd!
  autocmd BufNewFile,BufRead hosts setfiletype yaml.ansible
augroup END

This plugin should be quite reliable, as it sources the original formats and simply modifies the highlights as appropriate. This also enables a focus on simplicity and configurability instead of patching bad syntax detection.

examples (with solarized colorscheme)

Bright (and selective highlight)Dim

installation

Use your favorite plugin manager, or try vim-plug if you're looking for a really nice one!

vim-plug: Plug 'pearofducks/ansible-vim'

vim-plug with post-update hook: Plug 'pearofducks/ansible-vim', { 'do': './UltiSnips/generate.sh' }

Note: Because of Ansible API changes, generate.sh may require the latest (or near-latest) version of Ansible.

Note2: generate.sh can receive some parameters, for more info see its Readme

vundle: Plugin 'pearofducks/ansible-vim'

pathogen: git clone https://github.com/pearofducks/ansible-vim ~/.vim/bundle/ansible-vim

Arch Linux: Package vim-ansible is available in the community repository.

Fedora: The vim-ansible package is available in the default repository.

RHEL/CentOS: The vim-ansible package is available in the EPEL repository.

options

g:ansible_unindent_after_newline

let g:ansible_unindent_after_newline = 1

When this variable is set, indentation will completely reset (unindent to column 0) after two newlines in insert-mode. The normal behavior of YAML is to always keep the previous indentation, even across multiple newlines with no content.

g:ansible_yamlKeyName

let g:ansible_yamlKeyName = 'yamlKey'

This option exists to provide additional compatibility with stephpy/vim-yaml.

g:ansible_attribute_highlight

let g:ansible_attribute_highlight = "ob"

Ansible modules use a key=value format for specifying module-attributes in playbooks. This highlights those as specified. This highlight option is also used when highlighting key/value pairs in hosts files.

Available flags (bold are defaults):

  • a: highlight all instances of key=
  • o: highlight only instances of key= found on newlines
  • d: dim the instances of key= found
  • b: brighten the instances of key= found
  • n: turn this highlight off completely

g:ansible_name_highlight

let g:ansible_name_highlight = 'd'

Ansible modules commonly start with a name: key for self-documentation of playbooks. This option enables/changes highlight of this.

Available flags (this feature is off by default):

  • d: dim the instances of name: found
  • b: brighten the instances of name: found

g:ansible_extra_keywords_highlight

let g:ansible_extra_keywords_highlight = 1

Note: This option is enabled when set, and disabled when not set.

Highlight the following additional keywords: become become_exe become_flags become_method become_user become_pass prompt_l10n debugger always_run check_mode diff no_log args tags force_handlers vars vars_files vars_prompt delegate_facts delegate_to any_errors_fatal ignore_errors ignore_unreachable max_fail_percentage connection hosts port remote_user module_defaults environment fact_path gather_facts gather_subset gather_timeout async poll throttle timeout order run_once serial strategy.

By default we only highlight: include include_role include_tasks include_vars import_role import_playbook import_tasks when changed_when failed_when block rescue always notify listen register action local_action post_tasks pre_tasks tasks handlers roles collections and loop keywords with_.+, loop, loop_control, until, retries, delay.

g:ansible_extra_keywords_highlight_group

let g:ansible_extra_keywords_highlight_group = 'Statement'

Accepts any syntax group name from :help E669 - e.g. Comment, Constant, Identifier

Note: Defaults to 'Structure' when not set.

g:ansible_normal_keywords_highlight

let g:ansible_normal_keywords_highlight = 'Constant'

Accepts any syntax group name from :help E669 - e.g. Comment, Constant, Identifier

Note: Defaults to 'Statement' when not set.

This option change the highlight of the following common keywords: include include_role include_tasks include_vars import_role import_playbook import_tasks when changed_when failed_when block rescue always notify listen register action local_action post_tasks pre_tasks tasks handlers roles collections.

g:ansible_loop_keywords_highlight

let g:ansible_loop_keywords_highlight = 'Constant'

Accepts any syntax group-name from :help E669 - e.g. Comment, Constant, Identifier

Note: Defaults to 'Statement' when not set.

This option changes the highlight of all with_.+, loop, loop_control, until, retries and delay keywords.

g:ansible_template_syntaxes

let g:ansible_template_syntaxes = { '*.rb.j2': 'ruby' }

Accepts a dictionary in the form of 'regex-for-file': 'filetype'.

  • regex-for-file will receive the full filepath, so directory matching can be done.
  • filetype is the root filetype to be applied, jinja2 will be automatically appended

All files ending in *.j2 that aren't matched will simply get the jinja2 filetype.

g:ansible_ftdetect_filename_regex

let g:ansible_ftdetect_filename_regex = '\v(playbook|site|main|local|requirements)\.ya?ml$'

Accepts a regex string that is used to match the filename to determine if the file should use the Ansible filetype

Can be used to avoid clashes with other files that are named the same - e.g. main.yaml used in github workflows by removing main from the regex

goto role under cursor (similar to gf)

This behavior is not supported out of the box, but you can use this snippet in your vimrc.

You'll then be able to go to a role's definition with <leader>gr.

bugs, suggestions/requests, & contributions

bugs

It's unlikely that there will be bugs in highlighting that don't exist in the core format. Where appropriate these will be fixed in this plugin, but if the problem is with the original syntax we should probably focus on fixing that instead.

Indenting a full document - e.g with gg=G - will not be supported and is not a goal of this plugin (unless someone else develops it!). Please do not file a bug report on this.

suggestions/requests

Suggestions for improvements are welcome, pull-requests with completed features even more so. :)


Download Details:

Author: pearofducks
Source Code: https://github.com/pearofducks/ansible-vim

License: MIT license

#ansible