ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    YAML terminology and Ansible

    Training
    yaml ansible
    9
    20
    2.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • EddieJenningsE
      EddieJennings
      last edited by

      I want to make sure I'm using the right terminology for YAML syntax while learning to use Ansible. Consider the following playbook.

      According to this reference, about Ansible syntax the below contains the following:

      1. There is a list of dictionaries which would be the playbooks, of which there is one playbook named Have some fun with Ansible!
      2. The playbook Have some fun with Ansible is a dictionary which contains the following dictionaries (key value pairs):
        a. a hosts dictionary with the value labservers
        b. a become key with the boolean value true
        c. a list of dictionaries named tasks
      3. The tasks dictionary contains a list of four dictionaries, each with a name, and each with a dictionary describing a particular ansible module.
      ---
      - name: Have some fun with Ansible!
        hosts: labservers
        become: true
        tasks:
          - name: Create the file to be written
            file:
              path: /tmp/testfile
              state: touch
          - name: Write text to the file
            lineinfile:
              path: /tmp/testfile
              line:  Here's a test file!
          - name: Let's install git and Apache
            yum:
              name: git,httpd
              state: latest
          - name: Let's enable Apache and start it
            service:
              name: httpd
              state: started
              enabled: true
      ...
      
      1 Reply Last reply Reply Quote 1
      • M
        marcinozga
        last edited by

        And why would you care about terminology? Do you intend on teaching Ansible? It's the end result that matters, whether your playbook or role does what you want it to do, not whether you know the terminology or not. I've been using Ansible for some years, and honestly this is the first time I run into someone mentioning "dictionary".

        DustinB3403D EddieJenningsE ObsolesceO stacksofplatesS 4 Replies Last reply Reply Quote -3
        • DustinB3403D
          DustinB3403 @marcinozga
          last edited by DustinB3403

          @marcinozga So he can understand what the software does and actually comprehend what he's using.

          Also @EddieJennings makes training videos and would like to actually understand what he's discussing.

          1 Reply Last reply Reply Quote 2
          • EddieJenningsE
            EddieJennings @marcinozga
            last edited by

            @marcinozga said in YAML terminology and Ansible:

            And why would you care about terminology? Do you intend on teaching Ansible? It's the end result that matters, whether your playbook or role does what you want it to do, not whether you know the terminology or not. I've been using Ansible for some years, and honestly this is the first time I run into someone mentioning "dictionary".

            Terminology is important. It allows you to describe something clearly. Also, knowing the terms sometimes help piece together the logic of how something is working. When I'm learning something, simply making it work isn't sufficient for me.

            For your other question, at some point I probably will do some teaching. I like to share what I learn with others.

            1 Reply Last reply Reply Quote 2
            • JaredBuschJ
              JaredBusch
              last edited by

              Any idiot can search Google and then copy and paste crap and actually make things at work. It does not mean they have a fucking clue what they’re actually doing.

              DustinB3403D 1 Reply Last reply Reply Quote 2
              • DustinB3403D
                DustinB3403 @JaredBusch
                last edited by

                @JaredBusch said in YAML terminology and Ansible:

                Any idiot can search Google and then copy and paste crap and actually make things at work. It does not mean they have a fucking clue what they’re actually doing.

                Also known as Script Kiddies.

                People who find shit online and use it without taking the time to understand what it does and how it works.

                1 Reply Last reply Reply Quote 1
                • F
                  flaxking
                  last edited by

                  Speaking to just the YAML side of things and not Ansible, you've got it pretty good, just a few minor clarifications:

                  1. a. hosts is a key within a dictionary, not a dictionary itself, looks like they might have just been a typo

                  2. c. I mean, you could think of that dictionary being named tasks, but getting technical, tasks is a key in a dictionary that has a dictionary as the value.

                  EddieJenningsE 1 Reply Last reply Reply Quote 1
                  • scottalanmillerS
                    scottalanmiller
                    last edited by

                    Also, Eddie likes to teach and to teach you need to know what to call it. Referring to everything as "this bit here" doesn't work well for too long.

                    EddieJenningsE 1 Reply Last reply Reply Quote 1
                    • EddieJenningsE
                      EddieJennings @flaxking
                      last edited by

                      @flaxking said in YAML terminology and Ansible:

                      Speaking to just the YAML side of things and not Ansible, you've got it pretty good, just a few minor clarifications:

                      1. a. hosts is a key within a dictionary, not a dictionary itself, looks like they might have just been a typo

                      That makes sense. It wasn't a typo, and I thought it odd that hosts would be its own dictionary. In fact, hosts: labservers would be a key pair within the dictionary that begins with the first list item of - name: Have some fun with Ansible!, correct?

                      1. c. I mean, you could think of that dictionary being named tasks, but getting technical, tasks is a key in a dictionary that has a dictionary as the value.

                      Yes, yes. And that goes along with the first point you mentioned. The key tasks has a value which is a list of dictionaries, each beginning with the name specified, whose keys and values define the module being used.

                      1 Reply Last reply Reply Quote 0
                      • EddieJenningsE
                        EddieJennings @scottalanmiller
                        last edited by

                        @scottalanmiller said in YAML terminology and Ansible:

                        Also, Eddie likes to teach and to teach you need to know what to call it. Referring to everything as "this bit here" doesn't work well for too long.

                        True. The "this bit here" test is a quick way to assess your actual understanding.

                        1 Reply Last reply Reply Quote 0
                        • ObsolesceO
                          Obsolesce @marcinozga
                          last edited by

                          @marcinozga said in YAML terminology and Ansible:

                          And why would you care about terminology? Do you intend on teaching Ansible?

                          It's not just about Ansible, the same basic YAML is used to define YAML based CI/CD pipelines, and it's very helpful to know the proper terminology and syntax. There are may use cases besides Ansible playbooks.

                          Some of the basic syntax is similar in others such as JSON, as well as scripting languages. For example, maybe you're familiar with hash tables in PowerShell? It's all connected.

                          1 Reply Last reply Reply Quote 0
                          • 1
                            1337
                            last edited by 1337

                            According to the YAML spec there is no such a thing as a dictionary. That is python terminology, not YAML. Every programming language calls it a different thing like a collection, map, associative array etc.

                            So if you want to be precise you should look at the YAML spec.

                            ObsolesceO 1 Reply Last reply Reply Quote 1
                            • stacksofplatesS
                              stacksofplates @marcinozga
                              last edited by

                              @marcinozga said in YAML terminology and Ansible:

                              And why would you care about terminology? Do you intend on teaching Ansible? It's the end result that matters, whether your playbook or role does what you want it to do, not whether you know the terminology or not. I've been using Ansible for some years, and honestly this is the first time I run into someone mentioning "dictionary".

                              I've been using it since around 1.8 and I'm not sure how you haven't heard the term dictionary.

                              They reference it in the YAML basics of their docs: https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html

                              1 Reply Last reply Reply Quote 0
                              • ObsolesceO
                                Obsolesce @1337
                                last edited by

                                @Pete-S said in YAML terminology and Ansible:

                                According to the YAML spec there is no such a thing as a dictionary. That is python terminology, not YAML. Every programming language calls it a different thing like a collection, map, associative array etc.

                                So if you want to be precise you should look at the YAML spec.

                                We'll what do you know, right there in the 3rd paragraph of the YAML spec, they refer to it exactly as hashes/dictionaries....

                                Why bother to comment on something you know nothing about?

                                1 1 Reply Last reply Reply Quote 0
                                • 1
                                  1337 @Obsolesce
                                  last edited by 1337

                                  @Obsolesce said in YAML terminology and Ansible:

                                  @Pete-S said in YAML terminology and Ansible:

                                  According to the YAML spec there is no such a thing as a dictionary. That is python terminology, not YAML. Every programming language calls it a different thing like a collection, map, associative array etc.

                                  So if you want to be precise you should look at the YAML spec.

                                  We'll what do you know, right there in the 3rd paragraph of the YAML spec, they refer to it exactly as hashes/dictionaries....

                                  Why bother to comment on something you know nothing about?

                                  I comment because I know it's called a dictionary in Python and dictionary is not a universal name.
                                  And YAML is programming language agnostic. Other than that it doesn't matter to me what anyone calls it.


                                  3.1.1. Dump

                                  Dumping native data structures to a character stream is done using the following three stages:

                                  Representing Native Data Structures

                                  YAML represents any native data structure using three node kinds: sequence - an ordered series of entries; mapping - an unordered association of unique keys to values; and scalar - any datum with opaque structure presentable as a series of Unicode characters. Combined, these primitives generate directed graph structures. These primitives were chosen because they are both powerful and familiar: the sequence corresponds to a Perl array and a Python list, the mapping corresponds to a Perl hash table and a Python dictionary. The scalar represents strings, integers, dates, and other atomic data types.

                                  ObsolesceO 2 Replies Last reply Reply Quote 0
                                  • ObsolesceO
                                    Obsolesce @1337
                                    last edited by Obsolesce

                                    @Pete-S said in YAML terminology and Ansible:

                                    @Obsolesce said in YAML terminology and Ansible:

                                    @Pete-S said in YAML terminology and Ansible:

                                    According to the YAML spec there is no such a thing as a dictionary. That is python terminology, not YAML. Every programming language calls it a different thing like a collection, map, associative array etc.

                                    So if you want to be precise you should look at the YAML spec.

                                    We'll what do you know, right there in the 3rd paragraph of the YAML spec, they refer to it exactly as hashes/dictionaries....

                                    Why bother to comment on something you know nothing about?

                                    I comment because I know it's called a dictionary in Python and dictionary is not a universal name.
                                    And YAML is programming language agnostic. Other than that it doesn't matter to me what anyone calls it.


                                    3.1.1. Dump

                                    Dumping native data structures to a character stream is done using the following three stages:

                                    Representing Native Data Structures

                                    YAML represents any native data structure using three node kinds: sequence - an ordered series of entries; mapping - an unordered association of unique keys to values; and scalar - any datum with opaque structure presentable as a series of Unicode characters. Combined, these primitives generate directed graph structures. These primitives were chosen because they are both powerful and familiar: the sequence corresponds to a Perl array and a Python list, the mapping corresponds to a Perl hash table and a Python dictionary. The scalar represents strings, integers, dates, and other atomic data types.

                                    3rd paragraph of the YAML spec, go to the introduction, 3rd paragraph down....
                                    e991ea0c-421a-4e20-954a-836f477fe674-image.png

                                    1 Reply Last reply Reply Quote 0
                                    • ObsolesceO
                                      Obsolesce @1337
                                      last edited by Obsolesce

                                      @Pete-S said in YAML terminology and Ansible:

                                      Other than that it doesn't matter to me what anyone calls it.

                                      You are 100% free to call it whatever you want. But a key/value pair is commonly referred to as a dictionary... or a hash table which is a dictionary data type. This isn't exclusive to Python in the least.

                                      1 1 Reply Last reply Reply Quote 0
                                      • 1
                                        1337 @Obsolesce
                                        last edited by

                                        @Obsolesce said in YAML terminology and Ansible:

                                        @Pete-S said in YAML terminology and Ansible:

                                        Other than that it doesn't matter to me what anyone calls it.

                                        You are 100% to call it whatever you want. But a key/value pair is commonly referred to as a dictionary... or a hash table which is a dictionary data type. This isn't exclusive to Python in the least.

                                        "Commonly referred" depends on the programming language in question. For example in many other languages it's commonly called an array or collection and never a dictionary.

                                        If you look at the part you quoted, YAML calls it mappings.

                                        The proper computer science terminology would be associative array.
                                        https://en.wikipedia.org/wiki/Associative_array

                                        ObsolesceO 1 Reply Last reply Reply Quote 0
                                        • ObsolesceO
                                          Obsolesce @1337
                                          last edited by

                                          @Pete-S said in YAML terminology and Ansible:

                                          @Obsolesce said in YAML terminology and Ansible:

                                          @Pete-S said in YAML terminology and Ansible:

                                          Other than that it doesn't matter to me what anyone calls it.

                                          You are 100% to call it whatever you want. But a key/value pair is commonly referred to as a dictionary... or a hash table which is a dictionary data type. This isn't exclusive to Python in the least.

                                          "Commonly referred" depends on the programming language in question. For example in many other languages it's commonly called an array or collection and never a dictionary.

                                          If you look at the part you quoted, YAML calls it mappings.

                                          The proper computer science terminology would be associative array.
                                          https://en.wikipedia.org/wiki/Associative_array

                                          The best thing to do is to call it exactly what the language or software you are referring to calls it. If Ansible wants you to create what it has named in their documentation as a dictionary in YAML, that's what you refer to it as. Otherwise, someone who is familiar with Ansible and it's documentation won't know what the hell you are talking about if you call it your own thing.

                                          1 1 Reply Last reply Reply Quote 0
                                          • 1
                                            1337 @Obsolesce
                                            last edited by 1337

                                            @Obsolesce said in YAML terminology and Ansible:

                                            @Pete-S said in YAML terminology and Ansible:

                                            @Obsolesce said in YAML terminology and Ansible:

                                            @Pete-S said in YAML terminology and Ansible:

                                            Other than that it doesn't matter to me what anyone calls it.

                                            You are 100% to call it whatever you want. But a key/value pair is commonly referred to as a dictionary... or a hash table which is a dictionary data type. This isn't exclusive to Python in the least.

                                            "Commonly referred" depends on the programming language in question. For example in many other languages it's commonly called an array or collection and never a dictionary.

                                            If you look at the part you quoted, YAML calls it mappings.

                                            The proper computer science terminology would be associative array.
                                            https://en.wikipedia.org/wiki/Associative_array

                                            The best thing to do is to call it exactly what the language or software you are referring to calls it. If Ansible wants you to create what it has named in their documentation as a dictionary in YAML, that's what you refer to it as. Otherwise, someone who is familiar with Ansible and it's documentation won't know what the hell you are talking about if you call it your own thing.

                                            I can agree with that point of view - YAML in the context of Ansible.
                                            https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html

                                            So you'd call it dictionaries then. And lists.

                                            1 Reply Last reply Reply Quote 0
                                            • 1 / 1
                                            • First post
                                              Last post