Ansible: set facts using conditionals

แชร์
ฝัง
  • เผยแพร่เมื่อ 8 ม.ค. 2025
  • Ansible - Set_facts contional example
    Checkout all the code on my gist: gist.github.co...
    In ansible, like any other programming language, at some point, we’ll want to set a variable for something. This is fairly simple to do when it’s just one value, but if we need to pick that value from the server we run ansible against, it gets a bit trickier.
    For example:
    I’m running my playbook/role against a list of servers. I need to be able to identify which DC each server is in so I can apply the correct nameservers, timeservers, nfs mounts points, and anything else. I want my code to run on all the servers, set the fact based on something unique to that server, and then apply the configuration.
    In this video I’ll show you the following:
    • How to generate static facts
    • How to use a conditional statement to set a fact
    • How to combine the facts into a string

ความคิดเห็น • 14

  • @cliffcampbell83
    @cliffcampbell83 5 หลายเดือนก่อน

    Great concise explanation. Thanks

  • @kenhitchcock4075
    @kenhitchcock4075 3 ปีที่แล้ว +1

    Good stuff Dennis, good explanation.

    • @LondonIAC
      @LondonIAC  3 ปีที่แล้ว +1

      Thanks Ken.

  • @asaac7
    @asaac7 3 ปีที่แล้ว +2

    Nice explanation

    • @LondonIAC
      @LondonIAC  3 ปีที่แล้ว +1

      thanks, I'm glad it was helpful!

  • @RobertLugg
    @RobertLugg หลายเดือนก่อน

    Why not use vars instead of set_facts?

  • @piyush42962
    @piyush42962 2 ปีที่แล้ว +1

    Very nice video. Thanks

    • @LondonIAC
      @LondonIAC  2 ปีที่แล้ว

      Thanks. I'm glad you like it and I hope it was useful.

  • @tommymogensen8456
    @tommymogensen8456 2 ปีที่แล้ว +1

    Very useful - thank you.

    • @LondonIAC
      @LondonIAC  2 ปีที่แล้ว

      Glad it was helpful!

  • @rajneeshDBA
    @rajneeshDBA 2 ปีที่แล้ว

    Why assert conditions are not printing anything

    • @LondonIAC
      @LondonIAC  2 ปีที่แล้ว

      Hi Raj, I don't use "assert" in this demo. Do you mean one of my other videos?

  • @RABWA333
    @RABWA333 3 ปีที่แล้ว

    Nice video, thanks

    • @LondonIAC
      @LondonIAC  3 ปีที่แล้ว

      Glad you liked it!