Last active
August 1, 2018 19:46
-
-
Save davemcphee/c42e6fdec99c074eee092d70eb2c2660 to your computer and use it in GitHub Desktop.
ansible cheat sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# check if a string contains any substrings from a list | |
our_string: 'alexander graham cracker' | |
our_list: ['alex', 'barry', 'chris'] | |
check_result_bool: '{{ our_list | select("in", our_string) | list | count > 0 }}' | |
# using a dictionary with version keys and selecting the highest appropriate key / options | |
our_version = '6.2.5' | |
version_options_dict: | |
'6.5': [ 'an option for 6.5', 'something else' ] | |
'6.0': [ 'something else', 'and another' ] | |
'5.9': ['somthing else entirely' ] | |
{% set our_options_max_version = version_options_dict.keys() | select('version_compare', our_version, '<=') | max %} | |
{% set our_options = version_options_dict[our_options_max_version] %} | |
Options {{ our_options | join(",") }} | |
# get ansible to slurp a (few) file(s) into a variable, with globs! | |
slurp: '{{ lookup("pipe","cat {{ role_path }}/files/*.extension") }}' | |
# object / dictionary lookup filters | |
nosuid_mounted_usr_filesystems: '{{ ansible_mounts | selectattr("mount", "equalto", "/usr") | selectattr("options", "search", "nosuid") | list }}' | |
# delete a substring from a string / remove an item from a list | |
modified_string: '{{ item.options.split(",") | difference(["nosuid"]) | join(",") }}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment