Compare two variables in Ansible [duplicate]












-1
















This question already has an answer here:




  • Ansible: compare variables

    1 answer




I am writing a script to change passwords on multiple servers. The script accepts username and password as input.



It should ask for password twice and compare if they are equal.



I could not find a way to compare two variables. Here's what I have at the moment:



 vars_prompt:
- name: user_name
prompt: Enter the user name for password reset
private: no

- name: pass
prompt: Enter the password

- name: re-pass
prompt: Re-enter the password

tasks:

- name: Verify Password
debug:
msg: "Equal"
when: pass is match re-pass









share|improve this question















marked as duplicate by nwinkler, Matthew L Daniel, Community Dec 6 '18 at 15:04


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.























    -1
















    This question already has an answer here:




    • Ansible: compare variables

      1 answer




    I am writing a script to change passwords on multiple servers. The script accepts username and password as input.



    It should ask for password twice and compare if they are equal.



    I could not find a way to compare two variables. Here's what I have at the moment:



     vars_prompt:
    - name: user_name
    prompt: Enter the user name for password reset
    private: no

    - name: pass
    prompt: Enter the password

    - name: re-pass
    prompt: Re-enter the password

    tasks:

    - name: Verify Password
    debug:
    msg: "Equal"
    when: pass is match re-pass









    share|improve this question















    marked as duplicate by nwinkler, Matthew L Daniel, Community Dec 6 '18 at 15:04


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





















      -1












      -1








      -1









      This question already has an answer here:




      • Ansible: compare variables

        1 answer




      I am writing a script to change passwords on multiple servers. The script accepts username and password as input.



      It should ask for password twice and compare if they are equal.



      I could not find a way to compare two variables. Here's what I have at the moment:



       vars_prompt:
      - name: user_name
      prompt: Enter the user name for password reset
      private: no

      - name: pass
      prompt: Enter the password

      - name: re-pass
      prompt: Re-enter the password

      tasks:

      - name: Verify Password
      debug:
      msg: "Equal"
      when: pass is match re-pass









      share|improve this question

















      This question already has an answer here:




      • Ansible: compare variables

        1 answer




      I am writing a script to change passwords on multiple servers. The script accepts username and password as input.



      It should ask for password twice and compare if they are equal.



      I could not find a way to compare two variables. Here's what I have at the moment:



       vars_prompt:
      - name: user_name
      prompt: Enter the user name for password reset
      private: no

      - name: pass
      prompt: Enter the password

      - name: re-pass
      prompt: Re-enter the password

      tasks:

      - name: Verify Password
      debug:
      msg: "Equal"
      when: pass is match re-pass




      This question already has an answer here:




      • Ansible: compare variables

        1 answer








      ansible






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 '18 at 7:09









      nwinkler

      33k16108128




      33k16108128










      asked Nov 26 '18 at 18:41









      SubuSubu

      31




      31




      marked as duplicate by nwinkler, Matthew L Daniel, Community Dec 6 '18 at 15:04


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









      marked as duplicate by nwinkler, Matthew L Daniel, Community Dec 6 '18 at 15:04


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


























          1 Answer
          1






          active

          oldest

          votes


















          0















          Could not find a way to compare two varaibles




          The thing you want is assert:, but you will also want to actually name your variable a python-compatible name, else you will have to use the "dict" syntax to access it all the time, which will become annoying:



          vars_prompt:
          - name: pass
          - name: re_pass
          tasks:
          - name: ensure passwords are equal
          assert:
          that:
          - pass == re_pass





          share|improve this answer



















          • 1





            Thanks Matthew. That worked:)

            – Subu
            Dec 6 '18 at 15:05


















          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0















          Could not find a way to compare two varaibles




          The thing you want is assert:, but you will also want to actually name your variable a python-compatible name, else you will have to use the "dict" syntax to access it all the time, which will become annoying:



          vars_prompt:
          - name: pass
          - name: re_pass
          tasks:
          - name: ensure passwords are equal
          assert:
          that:
          - pass == re_pass





          share|improve this answer



















          • 1





            Thanks Matthew. That worked:)

            – Subu
            Dec 6 '18 at 15:05
















          0















          Could not find a way to compare two varaibles




          The thing you want is assert:, but you will also want to actually name your variable a python-compatible name, else you will have to use the "dict" syntax to access it all the time, which will become annoying:



          vars_prompt:
          - name: pass
          - name: re_pass
          tasks:
          - name: ensure passwords are equal
          assert:
          that:
          - pass == re_pass





          share|improve this answer



















          • 1





            Thanks Matthew. That worked:)

            – Subu
            Dec 6 '18 at 15:05














          0












          0








          0








          Could not find a way to compare two varaibles




          The thing you want is assert:, but you will also want to actually name your variable a python-compatible name, else you will have to use the "dict" syntax to access it all the time, which will become annoying:



          vars_prompt:
          - name: pass
          - name: re_pass
          tasks:
          - name: ensure passwords are equal
          assert:
          that:
          - pass == re_pass





          share|improve this answer














          Could not find a way to compare two varaibles




          The thing you want is assert:, but you will also want to actually name your variable a python-compatible name, else you will have to use the "dict" syntax to access it all the time, which will become annoying:



          vars_prompt:
          - name: pass
          - name: re_pass
          tasks:
          - name: ensure passwords are equal
          assert:
          that:
          - pass == re_pass






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 27 '18 at 7:11









          Matthew L DanielMatthew L Daniel

          8,90612728




          8,90612728








          • 1





            Thanks Matthew. That worked:)

            – Subu
            Dec 6 '18 at 15:05














          • 1





            Thanks Matthew. That worked:)

            – Subu
            Dec 6 '18 at 15:05








          1




          1





          Thanks Matthew. That worked:)

          – Subu
          Dec 6 '18 at 15:05





          Thanks Matthew. That worked:)

          – Subu
          Dec 6 '18 at 15:05





          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks