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

    Solved Scripting - How do you store your credentials and call them later?

    IT Discussion
    shell script credentials hashing
    7
    79
    5.2k
    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.
    • DustinB3403D
      DustinB3403 @stacksofplates
      last edited by

      @stacksofplates said in Scripting - How do you store your credentials and call them later?:

      @DustinB3403 said in Scripting - How do you store your credentials and call them later?:

      @IRJ said in Scripting - How do you store your credentials and call them later?:

      I'm glad you found a solution, but have you considered ansible for tasks like this?

      Have you consider our lord and savor jesus christ?

      FFS man...

      Of course I have I just don't understand it as all of their documentation is god awful and I'd have to take numerous pounds of coke up the backdoor to understand what the hell I'm supposed to do.

      I don't know what you're on. It's some of the better documentation. I'd be interested to see what specific parts you are referencing.

      Specifically using it to administrator Apple OSX laptops and workstations is what I'm particularly interested in. We have very few linux systems here that would require automation on any scale.

      1 Reply Last reply Reply Quote 0
      • DustinB3403D
        DustinB3403
        last edited by

        Like 85-90% of this office is OSX, so anything to help reduce that overhead would be great. I've even posted here about looking at all of these automation tools and which was best and it turned into a this one is cool, but it doesn't do that one thing you absolutely need.

        1 Reply Last reply Reply Quote 0
        • DustinB3403D
          DustinB3403
          last edited by

          PS I learn from seeing and doing, rather than reading. Just as an FYI.

          ObsolesceO 1 Reply Last reply Reply Quote 0
          • DustinB3403D
            DustinB3403
            last edited by

            And the peanut gallery falls silent.

            1 Reply Last reply Reply Quote 0
            • stacksofplatesS
              stacksofplates
              last edited by stacksofplates

              So I admittedly don't know anything about Macs because I don't care to, but here is a simple way to do this with Ansible.

              ---
              - name: Set crap with scutil
                hosts: macs
                become: true
                user: dustin
                vars:
                  -computername: "this_computer_sucks"
              
                tasks:
                  - name: set computername
                    shell: "scutil --set ComputerName {{ computername }}"
              
                  - name: set hostname
                    shell: "scutil --set HostName {{ computername }}"
              
                  - name: set localhostname
                    shell: "scutil --set LocalHostName {{ computername }}"
              

              If spacing is off, I'm on my phone so suck it up.

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

                @stacksofplates so that seems simple enough, how do you put in the custom details like I am pushing to these 1 by 1?

                the office location, the expected user and the asset tag to create a single -computername ?

                Also since we're on it, how do you use tools like brew.sh to install and update third party software?

                IRJI stacksofplatesS 3 Replies Last reply Reply Quote 0
                • IRJI
                  IRJ @DustinB3403
                  last edited by

                  @DustinB3403 said in Scripting - How do you store your credentials and call them later?:

                  @IRJ said in Scripting - How do you store your credentials and call them later?:

                  I'm glad you found a solution, but have you considered ansible for tasks like this?

                  Have you consider our lord and savor jesus christ?

                  FFS man...

                  Of course I have I just don't understand it as all of their documentation is god awful and I'd have to take numerous pounds of coke up the backdoor to understand what the hell I'm supposed to do.

                  On a positive note, if you want to jump on a skype call some time or another I'd be happy to learn if you're willing to teach.

                  Chill out man. The whole point of being in IT community is to learn new things. There's always more than one way to skin a cat, it's not horrible knowing there are other options.

                  Ansible really isn't that difficult and you'll save a ton of time in the long run.

                  DustinB3403D 1 Reply Last reply Reply Quote 0
                  • DustinB3403D
                    DustinB3403 @IRJ
                    last edited by

                    @IRJ I'm salty because I've brought automation tools like Anisble, chef, puppet and salt up before and the only responses have been minimal at best.

                    Can we have an in-depth this is how to get started conversation?

                    1 Reply Last reply Reply Quote 0
                    • IRJI
                      IRJ @DustinB3403
                      last edited by

                      @DustinB3403 said in Scripting - How do you store your credentials and call them later?:

                      @stacksofplates so that seems simple enough, how do you put in the custom details like I am pushing to these 1 by 1?

                      the office location, the expected user and the asset tag to create a single -computername ?

                      Also since we're on it, how do you use tools like brew.sh to install and update third party software?

                      To answer this question, you need to edit ansible hosts file. You would add the IPs to the group. You can be as granular as you want

                      [macs]
                      192.0.2.101
                      192.0.2.102
                      192.0.2.103
                      
                      [linux]
                      192.0.2.201
                      192.0.2.202
                      
                      [macbooks]
                      192.0.2.102
                      192.0.2.103
                      
                      DustinB3403D 1 Reply Last reply Reply Quote 0
                      • IRJI
                        IRJ @stacksofplates
                        last edited by

                        @stacksofplates said in Scripting - How do you store your credentials and call them later?:

                        So I admittedly don't know anything about Macs because I don't care to, but here is a simple way to do this with Ansible.

                        ---
                        - name: Set crap with scutil
                          hosts: macs
                          become: true
                          user: dustin
                          vars:
                            -computername: "this_computer_sucks"
                        
                          tasks:
                            - name: set computername
                              shell: "scutil --set ComputerName {{ computername }}"
                        
                            - name: set hostname
                              shell: "scutil --set HostName {{ computername }}"
                        
                            - name: set localhostname
                              shell: "scutil --set LocalHostName {{ computername }}"
                        

                        If spacing is off, I'm on my phone so suck it up.

                        @DustinB3403 , he assumed you had a group named macs on this playbook.You can change that under hosts

                        1 Reply Last reply Reply Quote 0
                        • DustinB3403D
                          DustinB3403 @IRJ
                          last edited by

                          @IRJ Using an specific IP wouldn't work I'd have to use dhcp scopes and filter out Windows PCs from that.

                          IRJI 1 Reply Last reply Reply Quote 0
                          • IRJI
                            IRJ @DustinB3403
                            last edited by

                            @DustinB3403 said in Scripting - How do you store your credentials and call them later?:

                            @IRJ Using an specific IP wouldn't work I'd have to use dhcp scopes and filter out Windows PCs from that.

                            add hostnames?

                            DustinB3403D 1 Reply Last reply Reply Quote 0
                            • DustinB3403D
                              DustinB3403 @IRJ
                              last edited by

                              @IRJ said in Scripting - How do you store your credentials and call them later?:

                              @DustinB3403 said in Scripting - How do you store your credentials and call them later?:

                              @IRJ Using an specific IP wouldn't work I'd have to use dhcp scopes and filter out Windows PCs from that.

                              add hostnames?

                              Which of the 3 above names would you think apple considers the host name 🙂 and you want me to type out ~170 computer names? Ansible can't handle DHCP based clients?

                              1 Reply Last reply Reply Quote 0
                              • IRJI
                                IRJ
                                last edited by

                                Do you have dns?

                                DustinB3403D 1 Reply Last reply Reply Quote 0
                                • DustinB3403D
                                  DustinB3403 @IRJ
                                  last edited by

                                  @IRJ said in Scripting - How do you store your credentials and call them later?:

                                  Do you have dns?

                                  Yes

                                  1 Reply Last reply Reply Quote 0
                                  • IRJI
                                    IRJ
                                    last edited by

                                    You may be able to do something like this? @stacksofplates can probably chime in

                                    192.168.1.[1:254]

                                    stacksofplatesS 1 Reply Last reply Reply Quote 0
                                    • stacksofplatesS
                                      stacksofplates @DustinB3403
                                      last edited by

                                      @DustinB3403 said in Scripting - How do you store your credentials and call them later?:

                                      @stacksofplates so that seems simple enough, how do you put in the custom details like I am pushing to these 1 by 1?

                                      the office location, the expected user and the asset tag to create a single -computername ?

                                      Also since we're on it, how do you use tools like brew.sh to install and update third party software?

                                      There's a few different ways to approach it. A good simple way is to leverage your inventory and group_vars.

                                      Here's an example inventory:

                                      [florida]
                                      10.23.50.15 comp_user=Mary tag_number=000335
                                      osx1.fl.test.com ansible_host=10.23.50.16 comp_user=Sally tag_number=000678
                                      
                                      [california]
                                      10.55.12.34 comp_user=Pete tag_number=000446
                                      osx2.ca.test.com ansible_host=10.55.12.35 comp_user=Jim tag_number=000445
                                      
                                      [macs:children]
                                      florida
                                      california
                                      

                                      So here you have an inventory that defines 4 different hosts. You can reference a host by IP address/FQDN or by an alias. In this case osx1.fl.test.com and osx2.ca.test.com are aliases for the ansible_host variable. The hosts are grouped into 3 groups. One group is called florida and obviously has the two hosts for florida in it. The other group is called california and is similar. The third group is called macs and it has children which are florida and california. So all of the hosts in florida and california are also in the macs group.

                                      Variables are a big deal and there's now 22 places to set variables (please don't try to use them all at the same time) and they all have an order of presidence. Simpler is better. The group_vars directory holds files named after a group and does exactly what it sounds like. So here we could set up a group_vars file called florida and it would contain:

                                      location: florida
                                      dns_server: 1.2.3.4
                                      timezone: eastern
                                      

                                      We can have a file for california and it could contain:

                                      location: california
                                      dns_server: 2.3.4.5
                                      timezone: pacific
                                      

                                      Then in the playbook I referenced above you can use these facts (including variables in your inventory). There are magic variables that are always present on every system and you can gather facts about systems also. One of the magic variables is inventory_hostname which is the alias (or just the fqdn if you didn't set an alias). So in your example you could do this:

                                      ---
                                      - name: Set crap with scutil
                                        hosts: macs
                                        become: true
                                        user: dustin
                                      
                                        tasks:
                                          - name: set computername
                                            shell: "scutil --set ComputerName {{ comp_user }}{{ tag_number }}"
                                      
                                          - name: set hostname
                                            shell: "scutil --set HostName {{ location }}{{ inventory_hostname }}"
                                      
                                          - name: set localhostname
                                            shell: "scutil --set LocalHostName {{ location }}{{ comp_user }}{{ tag_number }}"
                                      

                                      The comp_user and tag_number variables can be set in a directory called host_vars and a file named after the host name, but I don't commonly use that.

                                      1 Reply Last reply Reply Quote 2
                                      • stacksofplatesS
                                        stacksofplates @IRJ
                                        last edited by stacksofplates

                                        @IRJ said in Scripting - How do you store your credentials and call them later?:

                                        You may be able to do something like this? @stacksofplates can probably chime in

                                        192.168.1.[1:254]

                                        You can do something like that and even mac[1:3000].test.com, but it's valuable to have each system defined so you can control variables for each one. It's fairly trivial to export from your asset management system and make an inventory from that.

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

                                          @stacksofplates said in Scripting - How do you store your credentials and call them later?:

                                          @IRJ said in Scripting - How do you store your credentials and call them later?:

                                          You may be able to do something like this? @stacksofplates can probably chime in

                                          192.168.1.[1:254]

                                          You can do something like that and even mac[1:3000].test.com, but it's valuable to have each system defined so you can control variables for each one. It's fairly trivial to export from your asset management system and make an inventory from that.

                                          This is only true if I get to hit my coworker with a hammer

                                          1 Reply Last reply Reply Quote 0
                                          • stacksofplatesS
                                            stacksofplates @DustinB3403
                                            last edited by

                                            @DustinB3403 said in Scripting - How do you store your credentials and call them later?:

                                            @stacksofplates so that seems simple enough, how do you put in the custom details like I am pushing to these 1 by 1?

                                            the office location, the expected user and the asset tag to create a single -computername ?

                                            Also since we're on it, how do you use tools like brew.sh to install and update third party software?

                                            For brew there's a module to interact with it. You just declare the package you want installed and it does it.

                                            - name: Ensure foo is installed
                                              homebrew:
                                                name: foo
                                                state: present
                                            

                                            You can also do multiple:

                                            - name: Ensure packages are installed
                                              homebrew:
                                                name: "{{ item }}"
                                                state: present
                                              loop:
                                                - softwareA
                                                - softwareB
                                                - softwareC
                                            DustinB3403D 1 Reply Last reply Reply Quote 0
                                            • 1
                                            • 2
                                            • 3
                                            • 4
                                            • 3 / 4
                                            • First post
                                              Last post