Ansible-Playbook run custom group_vars












1















Im newbie using ansible.



I am trying to execute a custom playbook, which executes the roles that have been mounted from an iso, for this I have the following structure.



- /iso/
- /AnsibleFiles/
- /roles/
- ....
- ....

- myPlaybook.yml
- /myInventory/
- group_vars/
- myInventoryFile




  • myPlaybook.yml: It has where my roles are, and which have to execute.


  • myInventoryFile: It has the variables that I need to execute the roles.


Im trying to execute like this:



ansible-playbook myPlaybook.yml -i myInventory/group_vars/myInventoryFile


But itdoes not work.. ansible dont read my vars, return this message:



The conditional check '{{ my_Var }}' failed. The error was: error while evaluating conditional ({{ my_Var }}): 'my_Var ' is undefinednnThe error appears to have been in '/home/user/myPlaybook.yml


myInventoryFile



Have the variable defined like this: my_Var: true



myPlaybook.yml



It ave to evaluate this variable to know which roles to execute.



when: "{{my_Var}}"









share|improve this question





























    1















    Im newbie using ansible.



    I am trying to execute a custom playbook, which executes the roles that have been mounted from an iso, for this I have the following structure.



    - /iso/
    - /AnsibleFiles/
    - /roles/
    - ....
    - ....

    - myPlaybook.yml
    - /myInventory/
    - group_vars/
    - myInventoryFile




    • myPlaybook.yml: It has where my roles are, and which have to execute.


    • myInventoryFile: It has the variables that I need to execute the roles.


    Im trying to execute like this:



    ansible-playbook myPlaybook.yml -i myInventory/group_vars/myInventoryFile


    But itdoes not work.. ansible dont read my vars, return this message:



    The conditional check '{{ my_Var }}' failed. The error was: error while evaluating conditional ({{ my_Var }}): 'my_Var ' is undefinednnThe error appears to have been in '/home/user/myPlaybook.yml


    myInventoryFile



    Have the variable defined like this: my_Var: true



    myPlaybook.yml



    It ave to evaluate this variable to know which roles to execute.



    when: "{{my_Var}}"









    share|improve this question



























      1












      1








      1








      Im newbie using ansible.



      I am trying to execute a custom playbook, which executes the roles that have been mounted from an iso, for this I have the following structure.



      - /iso/
      - /AnsibleFiles/
      - /roles/
      - ....
      - ....

      - myPlaybook.yml
      - /myInventory/
      - group_vars/
      - myInventoryFile




      • myPlaybook.yml: It has where my roles are, and which have to execute.


      • myInventoryFile: It has the variables that I need to execute the roles.


      Im trying to execute like this:



      ansible-playbook myPlaybook.yml -i myInventory/group_vars/myInventoryFile


      But itdoes not work.. ansible dont read my vars, return this message:



      The conditional check '{{ my_Var }}' failed. The error was: error while evaluating conditional ({{ my_Var }}): 'my_Var ' is undefinednnThe error appears to have been in '/home/user/myPlaybook.yml


      myInventoryFile



      Have the variable defined like this: my_Var: true



      myPlaybook.yml



      It ave to evaluate this variable to know which roles to execute.



      when: "{{my_Var}}"









      share|improve this question
















      Im newbie using ansible.



      I am trying to execute a custom playbook, which executes the roles that have been mounted from an iso, for this I have the following structure.



      - /iso/
      - /AnsibleFiles/
      - /roles/
      - ....
      - ....

      - myPlaybook.yml
      - /myInventory/
      - group_vars/
      - myInventoryFile




      • myPlaybook.yml: It has where my roles are, and which have to execute.


      • myInventoryFile: It has the variables that I need to execute the roles.


      Im trying to execute like this:



      ansible-playbook myPlaybook.yml -i myInventory/group_vars/myInventoryFile


      But itdoes not work.. ansible dont read my vars, return this message:



      The conditional check '{{ my_Var }}' failed. The error was: error while evaluating conditional ({{ my_Var }}): 'my_Var ' is undefinednnThe error appears to have been in '/home/user/myPlaybook.yml


      myInventoryFile



      Have the variable defined like this: my_Var: true



      myPlaybook.yml



      It ave to evaluate this variable to know which roles to execute.



      when: "{{my_Var}}"






      ansible ansible-inventory






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 19 '18 at 7:51









      tlo

      83411525




      83411525










      asked Nov 16 '18 at 11:41









      AlberrBAlberrB

      305




      305
























          2 Answers
          2






          active

          oldest

          votes


















          0














          I got the following to work.



          I created the following directory structure:



          .
          + AnsibleFiles
          | + roles
          | + testmyvar
          | + tasks
          | + main.yml
          + myInventory
          | + localhost
          + myPlaybook.yml


          The content of AnsibleFiles/roles/testmyvar/tasks/main.yml:



          ---
          - name: Checking value of my_Var
          debug: var=my_Var
          ...


          The content of myInventory/localhost:



          localhost my_Var=yuck


          The content of myPlaybook.yml



          ---
          - hosts: localhost
          roles:
          - AnsibleFiles/roles/testmyvar
          ...


          I get the following when I run the following command:



          me$ ansible-playbook -i ./myInventory/localhost ./myPlaybook.yml

          PLAY [localhost] ***************************************************************

          TASK [Gathering Facts] *********************************************************
          ok: [localhost]

          TASK [AnsibleFiles/roles/testmyvar : Checking value of my_Var] *****************
          ok: [localhost] => {
          "my_Var": "yuck"
          }

          PLAY RECAP *********************************************************************
          localhost : ok=2 changed=0 unreachable=0 failed=0


          I do not think you can have a group_vars directory and specify that with the -i on the command line. From what I read, you must have an inventory file. That means everything must be in that inventory file, including the vars definitions.



          Hopefully this provides some guidance on how to update your Ansible code.






          share|improve this answer
























          • Ty! Its works I dont have in my inventory file "localhost" my_var=value

            – AlberrB
            Nov 16 '18 at 13:44



















          1














          inventory file: ansible-playbook myPlaybook.yml -i /etc/ansible/inventory/myInventory.yml



          group vars folder/file: /etc/ansible/inventory/group_vars/myInventory.yml / /etc/ansible/inventory/group_vars/myInventory/something.yml






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337168%2fansible-playbook-run-custom-group-vars%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I got the following to work.



            I created the following directory structure:



            .
            + AnsibleFiles
            | + roles
            | + testmyvar
            | + tasks
            | + main.yml
            + myInventory
            | + localhost
            + myPlaybook.yml


            The content of AnsibleFiles/roles/testmyvar/tasks/main.yml:



            ---
            - name: Checking value of my_Var
            debug: var=my_Var
            ...


            The content of myInventory/localhost:



            localhost my_Var=yuck


            The content of myPlaybook.yml



            ---
            - hosts: localhost
            roles:
            - AnsibleFiles/roles/testmyvar
            ...


            I get the following when I run the following command:



            me$ ansible-playbook -i ./myInventory/localhost ./myPlaybook.yml

            PLAY [localhost] ***************************************************************

            TASK [Gathering Facts] *********************************************************
            ok: [localhost]

            TASK [AnsibleFiles/roles/testmyvar : Checking value of my_Var] *****************
            ok: [localhost] => {
            "my_Var": "yuck"
            }

            PLAY RECAP *********************************************************************
            localhost : ok=2 changed=0 unreachable=0 failed=0


            I do not think you can have a group_vars directory and specify that with the -i on the command line. From what I read, you must have an inventory file. That means everything must be in that inventory file, including the vars definitions.



            Hopefully this provides some guidance on how to update your Ansible code.






            share|improve this answer
























            • Ty! Its works I dont have in my inventory file "localhost" my_var=value

              – AlberrB
              Nov 16 '18 at 13:44
















            0














            I got the following to work.



            I created the following directory structure:



            .
            + AnsibleFiles
            | + roles
            | + testmyvar
            | + tasks
            | + main.yml
            + myInventory
            | + localhost
            + myPlaybook.yml


            The content of AnsibleFiles/roles/testmyvar/tasks/main.yml:



            ---
            - name: Checking value of my_Var
            debug: var=my_Var
            ...


            The content of myInventory/localhost:



            localhost my_Var=yuck


            The content of myPlaybook.yml



            ---
            - hosts: localhost
            roles:
            - AnsibleFiles/roles/testmyvar
            ...


            I get the following when I run the following command:



            me$ ansible-playbook -i ./myInventory/localhost ./myPlaybook.yml

            PLAY [localhost] ***************************************************************

            TASK [Gathering Facts] *********************************************************
            ok: [localhost]

            TASK [AnsibleFiles/roles/testmyvar : Checking value of my_Var] *****************
            ok: [localhost] => {
            "my_Var": "yuck"
            }

            PLAY RECAP *********************************************************************
            localhost : ok=2 changed=0 unreachable=0 failed=0


            I do not think you can have a group_vars directory and specify that with the -i on the command line. From what I read, you must have an inventory file. That means everything must be in that inventory file, including the vars definitions.



            Hopefully this provides some guidance on how to update your Ansible code.






            share|improve this answer
























            • Ty! Its works I dont have in my inventory file "localhost" my_var=value

              – AlberrB
              Nov 16 '18 at 13:44














            0












            0








            0







            I got the following to work.



            I created the following directory structure:



            .
            + AnsibleFiles
            | + roles
            | + testmyvar
            | + tasks
            | + main.yml
            + myInventory
            | + localhost
            + myPlaybook.yml


            The content of AnsibleFiles/roles/testmyvar/tasks/main.yml:



            ---
            - name: Checking value of my_Var
            debug: var=my_Var
            ...


            The content of myInventory/localhost:



            localhost my_Var=yuck


            The content of myPlaybook.yml



            ---
            - hosts: localhost
            roles:
            - AnsibleFiles/roles/testmyvar
            ...


            I get the following when I run the following command:



            me$ ansible-playbook -i ./myInventory/localhost ./myPlaybook.yml

            PLAY [localhost] ***************************************************************

            TASK [Gathering Facts] *********************************************************
            ok: [localhost]

            TASK [AnsibleFiles/roles/testmyvar : Checking value of my_Var] *****************
            ok: [localhost] => {
            "my_Var": "yuck"
            }

            PLAY RECAP *********************************************************************
            localhost : ok=2 changed=0 unreachable=0 failed=0


            I do not think you can have a group_vars directory and specify that with the -i on the command line. From what I read, you must have an inventory file. That means everything must be in that inventory file, including the vars definitions.



            Hopefully this provides some guidance on how to update your Ansible code.






            share|improve this answer













            I got the following to work.



            I created the following directory structure:



            .
            + AnsibleFiles
            | + roles
            | + testmyvar
            | + tasks
            | + main.yml
            + myInventory
            | + localhost
            + myPlaybook.yml


            The content of AnsibleFiles/roles/testmyvar/tasks/main.yml:



            ---
            - name: Checking value of my_Var
            debug: var=my_Var
            ...


            The content of myInventory/localhost:



            localhost my_Var=yuck


            The content of myPlaybook.yml



            ---
            - hosts: localhost
            roles:
            - AnsibleFiles/roles/testmyvar
            ...


            I get the following when I run the following command:



            me$ ansible-playbook -i ./myInventory/localhost ./myPlaybook.yml

            PLAY [localhost] ***************************************************************

            TASK [Gathering Facts] *********************************************************
            ok: [localhost]

            TASK [AnsibleFiles/roles/testmyvar : Checking value of my_Var] *****************
            ok: [localhost] => {
            "my_Var": "yuck"
            }

            PLAY RECAP *********************************************************************
            localhost : ok=2 changed=0 unreachable=0 failed=0


            I do not think you can have a group_vars directory and specify that with the -i on the command line. From what I read, you must have an inventory file. That means everything must be in that inventory file, including the vars definitions.



            Hopefully this provides some guidance on how to update your Ansible code.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 16 '18 at 12:54









            Lewis MLewis M

            49815




            49815













            • Ty! Its works I dont have in my inventory file "localhost" my_var=value

              – AlberrB
              Nov 16 '18 at 13:44



















            • Ty! Its works I dont have in my inventory file "localhost" my_var=value

              – AlberrB
              Nov 16 '18 at 13:44

















            Ty! Its works I dont have in my inventory file "localhost" my_var=value

            – AlberrB
            Nov 16 '18 at 13:44





            Ty! Its works I dont have in my inventory file "localhost" my_var=value

            – AlberrB
            Nov 16 '18 at 13:44













            1














            inventory file: ansible-playbook myPlaybook.yml -i /etc/ansible/inventory/myInventory.yml



            group vars folder/file: /etc/ansible/inventory/group_vars/myInventory.yml / /etc/ansible/inventory/group_vars/myInventory/something.yml






            share|improve this answer




























              1














              inventory file: ansible-playbook myPlaybook.yml -i /etc/ansible/inventory/myInventory.yml



              group vars folder/file: /etc/ansible/inventory/group_vars/myInventory.yml / /etc/ansible/inventory/group_vars/myInventory/something.yml






              share|improve this answer


























                1












                1








                1







                inventory file: ansible-playbook myPlaybook.yml -i /etc/ansible/inventory/myInventory.yml



                group vars folder/file: /etc/ansible/inventory/group_vars/myInventory.yml / /etc/ansible/inventory/group_vars/myInventory/something.yml






                share|improve this answer













                inventory file: ansible-playbook myPlaybook.yml -i /etc/ansible/inventory/myInventory.yml



                group vars folder/file: /etc/ansible/inventory/group_vars/myInventory.yml / /etc/ansible/inventory/group_vars/myInventory/something.yml







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 16 '18 at 12:26









                rafal1337rafal1337

                667




                667






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337168%2fansible-playbook-run-custom-group-vars%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Academy of Television Arts & Sciences

                    L'Équipe

                    1995 France bombings