Monday, December 04, 2023

Running `go` From a Docker Container

 I followed instructions I found here: https://hub.docker.com/_/golang

% cat Dockerfile

FROM golang:1.21
WORKDIR /usr/src/app
# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify
COPY . .
RUN go build -v -o /usr/local/bin/app ./...
CMD ["app"]

You can use it like this ...

% cat hello.go
package main
import ("fmt")

func main() {
  fmt.Println("Hello World!")
}

% docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.21 go build /usr/src/myapp/hello.go

% docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp golang:1.21 /usr/src/myapp/hello
Hello World!


Saturday, August 12, 2023

Ansible Unit Test Molecule Invert Failure into Success

 This is the use case where you are expecting a task to fail during the unit test.  There are cases where you would want to test for this.  Use your imagination. 


Anyways add this to the end of your molecule/*/converge.yml file:

---
- name: Converge
  hosts: all
  vars:

    ... omitted ...

    task_that_should_fail: 'Check if web server returns 200 on localhost'
  tasks:

    ... omitted ...

    - name: Role Should Fail In This Test
      block:
        - name: Include my_role
          ansible.builtin.include_role:
            name: "my_role"
          ignore_errors: true

        - name: Passed is Fail
          fail:
            msg: "Role my_role unexpectedly successed!"

      rescue:
        - name: Failed is Pass
          debug:
            msg: "Role my_role failed when it should have!"
          when:
            - ansible_failed_task.name == task_that_should_fail

        - name: Passed is Fail
          fail:
            msg: "Role my_role unexpectedly succeed!"
          when:
            - not ansible_failed_task.name == task_that_should_fail

Wednesday, August 02, 2023

How to Add the Current Time to the Results of Your MySQL Select Statements

 MariaDB [xx_config]> select *, NOW() from servers where id = 'Fakeuuid-kinda'; 
| ID              |  VERSION |  NOW()    
| Thing One | Thing Two  | 2023-08-03 02:57:44 

Tuesday, August 01, 2023

What Data Directory is MariaDB 10.6 using?

 Run this SQL query ...

root@xoubdmz1:~ # mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 587
Server version: 10.6.14-MariaDB-1:10.6.14+maria~ubu2204-log mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like 'datadir';
+---------------+-----------------+
| Variable_name | Value           |
+---------------+-----------------+
| datadir       | /var/lib/mysql/ |
+---------------+-----------------+
1 row in set (0.001 sec)

MariaDB [(none)]>

Friday, June 16, 2023

vi mk%y'k

Copy lines of text between '{}'s 

Give this text file contents:

  1
  2 ; <<>> DiG 9.10.6 <<>> download.fedoraproject.org
  3 ;; global options: +cmd
  4 ;; Got answer:
  5 ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52209
  6 ;; flags: qr rd ra; QUERY: 1, ANSWER: 10, AUTHORITY: 0, ADDITIONAL: 1
  7
  8 ;; OPT PSEUDOSECTION:
  9 ; EDNS: version: 0, flags:; udp: 512
 10 ;; QUESTION SECTION:
 11 ;download.fedoraproject.org.    IN      A
 12 {
 13 ;; ANSWER SECTION:
 14 download.fedoraproject.org. 300 IN      CNAME   wildcard.fedoraproject.org.
 15 wildcard.fedoraproject.org. 22  IN      A       38.145.60.20
 16 wildcard.fedoraproject.org. 22  IN      A       152.19.134.142
 17 wildcard.fedoraproject.org. 22  IN      A       67.219.144.68
 18 wildcard.fedoraproject.org. 22  IN      A       8.43.85.67
 19 wildcard.fedoraproject.org. 22  IN      A       38.145.60.21
 20 wildcard.fedoraproject.org. 22  IN      A       152.19.134.198
 21 wildcard.fedoraproject.org. 22  IN      A       8.43.85.73
 22 wildcard.fedoraproject.org. 22  IN      A       140.211.169.196
 23 wildcard.fedoraproject.org. 22  IN      A       34.221.3.152
 24 }
 25 (
 26 ;; Query time: 95 msec
 27 ;; SERVER: 2600:6c52:763f:e773:1691:82ff:fe86:3046#53(2600:6c52:763f:e773:1691:82ff:fe86:3046)
 28 ;; WHEN: Fri Jun 16 21:31:33 PDT 2023
 29 ;; MSG SIZE  rcvd: 222
 30 )

Move the cursor to the '{' on line 12. (:12<return>) then type: mk%y'k then move the cursor to line 7 and type: p and the file should look like this:

  1
  2 ; <<>> DiG 9.10.6 <<>> download.fedoraproject.org
  3 ;; global options: +cmd
  4 ;; Got answer:
  5 ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 52209
  6 ;; flags: qr rd ra; QUERY: 1, ANSWER: 10, AUTHORITY: 0, ADDITIONAL: 1
  7 {
  8 ;; ANSWER SECTION:
  9 download.fedoraproject.org. 300 IN      CNAME   wildcard.fedoraproject.org.
 10 wildcard.fedoraproject.org. 22  IN      A       38.145.60.20
 11 wildcard.fedoraproject.org. 22  IN      A       152.19.134.142
 12 wildcard.fedoraproject.org. 22  IN      A       67.219.144.68
 13 wildcard.fedoraproject.org. 22  IN      A       8.43.85.67
 14 wildcard.fedoraproject.org. 22  IN      A       38.145.60.21
 15 wildcard.fedoraproject.org. 22  IN      A       152.19.134.198
 16 wildcard.fedoraproject.org. 22  IN      A       8.43.85.73
 17 wildcard.fedoraproject.org. 22  IN      A       140.211.169.196
 18 wildcard.fedoraproject.org. 22  IN      A       34.221.3.152
 19 }
 20
 21 ;; OPT PSEUDOSECTION:
 22 ; EDNS: version: 0, flags:; udp: 512
 23 ;; QUESTION SECTION:
 24 ;download.fedoraproject.org.    IN      A
 25 {
 26 ;; ANSWER SECTION:
 27 download.fedoraproject.org. 300 IN      CNAME   wildcard.fedoraproject.org.
 28 wildcard.fedoraproject.org. 22  IN      A       38.145.60.20
 29 wildcard.fedoraproject.org. 22  IN      A       152.19.134.142
 30 wildcard.fedoraproject.org. 22  IN      A       67.219.144.68
 31 wildcard.fedoraproject.org. 22  IN      A       8.43.85.67
 32 wildcard.fedoraproject.org. 22  IN      A       38.145.60.21
 33 wildcard.fedoraproject.org. 22  IN      A       152.19.134.198
 34 wildcard.fedoraproject.org. 22  IN      A       8.43.85.73
 35 wildcard.fedoraproject.org. 22  IN      A       140.211.169.196
 36 wildcard.fedoraproject.org. 22  IN      A       34.221.3.152
 37 }
 38 (
 39 ;; Query time: 95 msec
 40 ;; SERVER: 2600:6c52:763f:e773:1691:82ff:fe86:3046#53(2600:6c52:763f:e773:1691:82ff:fe86:3046)
...


Wednesday, June 07, 2023

Remove last column in bash

awk -F'.' 'sub(FS $NF,x)' file

bash-3.2$ cat file
MOR22A2.S4000011.h23v22.061.2023063111017.hdf
MOR22A2.S4000011.h23v44.061.2023061111033.hdf
AST006_S003.zip
AST003_S066.zip
bash-3.2$ awk -F'.' 'sub(FS $NF,x)' file
MOR22A2.S4000011.h23v22.061.2023063111017
MOR22A2.S4000011.h23v44.061.2023061111033
AST006_S003
AST003_S066