Skip to main content

Posts

Showing posts from June, 2021

Ansible - Utilize attributes defined on a per-item basis in a single task

When using conditionals in ansible, most of the time you'll use 'when' and specify which parameter should be checked. This can however result in a rather lengthy and confusing list of tasks that can be easily reduced. Here's an example of a list of tasks that create users: - name: create regular users | --password, --groups become: true loop: "{{ users }}" user: name: "{{ item.name }}" uid: "{{ item.uid }}" shell: "{{ item.shell | default('/bin/sh') }}" when: not item.groups is defined and not item.password is defined tags: - all - users - name: create regular users | --password, ++groups become: true loop: "{{ users }}" user: name: "{{ item.name }}" uid: "{{ item.uid }}" shell: "{{ item.shell | default('/bin/sh') }}" groups: "{{ item.groups }}" when: ite

Ansible - Use foreman as inventory source

When there's a foreman present in the environment, it's wise to use it as an inventory source for your ansible deployments since it will most likely always be up to date when it comes to hosts (single source of truth).  In order to use ansible as inventory, you'll have to define a *.foreman.yml file in your inventory which will then query the foreman for hosts, groups and variables which can then be used in ansible: [archy@ansible ~/ansible]$ vim inventories/foreman/archyslife.foreman.yml plugin: foreman url: https://katello.archyslife.lan user: roadmin password: !vault | $ANSIBLE_VAULT;1.1;AES256 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 000000000000000000000000000000000000000000000000000000000000000000000000000000

Kubernetes - Horizontal Pod autoscaling

Kubernetes has the ability to automatically scale resources as required by the current load. There are some prerequirements however. With a user-provisioned kubernetes cluster, there's most likely not going to be a metrics-server deployed: [archy@kube01 ~]$ kubectl -n kube-system get deployments -o wide NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR coredns 2/2 2 2 154d coredns k8s.gcr.io/coredns/coredns:v1.8.0 k8s-app=kube-dns To deploy the metrics-server, go ahead and download the manifest from GitHub: [archy@kube01 ~]$ curl -k -L -o kubernetes/metrics-server.yml -X GET 'https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml' In order to enable the metrics-server to communicate with the worker-nodes, we'll have to add the 'kubelet-insecure-tls' option to the manifest args and then apply it: [archy@kube01 ~]$ vim kube