Month: January 2020

  • Strange problem in puppet run for Ubuntu

    Hi,

    Short sharing of a strange case.

    We’ve written a small manifest in order to distribute some python scripts. You can find the reference here: https://medium.com/metrosystemsro/new-ground-automatic-increase-of-kafka-lvm-on-gcp-311633b0816c

    When you try to run it on Ubuntu 14.04, there is this very strange error:

    Error: Failed to apply catalog: [nil, nil, nil, nil, nil, nil]

    The cause for this is as follows:

    Python 3.4.3 (default, Nov 12 2018, 22:25:49)
    [GCC 4.8.4] on linux (and I believe this is the default max version on trusty)

    In order to install the dependencies, you need python3-pip, so a short search returns following options:

    apt search python3-pip
    Sorting... Done
    Full Text Search... Done
    python3-pip/trusty-updates,now 1.5.4-1ubuntu4 all [installed]
      alternative Python package installer - Python 3 version of the package
    
    python3-pipeline/trusty 0.1.3-3 all
      iterator pipelines for Python 3

    If we want to list all the installed modules with pip3 list, guess what, it’s not working:

    Traceback (most recent call last):
       File "/usr/bin/pip3", line 5, in 
         from pkg_resources import load_entry_point
       File "/usr/local/lib/python3.4/dist-packages/pkg_resources/init.py", line 93, in 
         raise RuntimeError("Python 3.5 or later is required")
     RuntimeError: Python 3.5 or later is required

    So, main conclusion is that it’s not related to puppet, just the incompatibility between version for this old distribution.

    Cheers

  • Small addition for ‘cat’ in Python

    Hi,

    There was a issue on options that aggregate any other ones, like -A for my previous post

    In my view the easiest way to solve it is by storing the options in a tuple.

    Here is the snippet

    run_options = []
    try:
        opts, args = getopt.gnu_getopt(sys.argv[1:-1], 'AbeEnstTv', ['show-all', 'number-nonblank', 'show-ends', 'number', 'show-blank', 'squeeze-blank' 'show-tabs', 'show-nonprinting', 'help', 'version'])
    except getopt.GetoptError:
         print("Something went wrong")
         sys.exit(2)
    for opt, arg in opts:
        if opt in ('-A','--show-all'):
            run_options.append('E')
            run_options.append('T')
        elif opt in ('-b', '--number-nonblank'):
            run_options.append('b')
        elif opt in ('-n', '--number'):
            run_options.append('n')
        elif opt in ('-E', '--show-ends'):
            run_options.append('E')
        elif opt in ('-s', '--squeeze-blank'):
            run_options.append('s')
        elif opt in ('-T', '--show-tabs'):
            run_options.append('T')
     
    final_run_options = tuple(run_options)
    for element in final_run_options:
        if element == 'b':
            content_list = number_nonempty_lines(content_list)
        elif element == 'n':
            content_list = number_all_lines(content_list)   
        elif element == 'E':
            content_list = display_endline(content_list)
        elif element == 's':
            content_list = squeeze_blanks(content_list)
        elif element == 'T':
            content_list = show_tabs(content_list)

    So basically, you store the actual cases in a list which you convert to a tuple to eliminate duplicates. Once you have the final case, you parse it and change the actual content option by option.

    I didn’t have the time to test it but there is no big reason why it should’t work.

    Cheers