Problem scenario
You want to use the du command without it recursing through subdirectories. How do you do this?
Solution
Run this command:du -h /path/to --max-depth=0
A Technical I.T./DevOps Blog
Problem scenario
You want to use the du command without it recursing through subdirectories. How do you do this?
Solution
Run this command:du -h /path/to --max-depth=0
Problem scenario
You want to use the "docker push" command. But you do not know how your Docker host is configured. You want to know what repository your Docker host is configured to use. How do you determine which repository your "docker push" commands will be destined to?
Solution
Docker push involves a destination Docker registry -- not a repository. A registry is a collection of Docker repositories (things that hold versions of Docker images). A repository can only hold one Docker image and its different versions.
"If no registry URI is specified, Docker will assume you intend to use or log out from Docker Hub." The source of this quote is here: https://docs.joyent.com/public-cloud/instances/docker/how/get-private-docker-images
If you want to use a different registry explicitly mention it in your Docker pull command.
To not use the docker.io registry, run these commands:
docker logoutdocker login <nameOfRegistry> If you want to push a Docker image to ECR, see "How do you upload a Docker image to Amazon Elastic Container registry?"
Problem scenario
You try to run an AWS CLI command. But you receive this error:
' File "/bin/aws-cli-1.16.226/bin/aws", line 19, in
import awscli.clidriver
ModuleNotFoundError: No module named 'awscli'
'
Solution
Did you run sudo python3 setup.py install ? If you only ran the build step, this could happen.
Problem scenario
You try to run an AWS CLI command but you receive this error: /usr/bin/env: ‘python’: No such file or directory
What should you do?
Possible Solution #1
If Python 3 is not installed, install it. You may want to see these postings:
How Do You Upgrade to Python 3.x on Ubuntu 16?
How Do You Upgrade Python 2.x to Python 3.7 in Debian or Ubuntu Linux?
Possible Solution #2
If Python 3 has been installed, run this command:whereis python3
# If the above did not work, try this: sudo find / -name python3 -type f
Run a command like this, but substitute /path/to/python3 with one of the results in the above command (e.g., /usr/bin/python3).
sudo ln -s /path/to/python3 /usr/bin/python
That should be it. You should now try to run your Python command again.
If you want to purchase a book on Python, please see this link.
Problem scenario
You want to create a kubeconfig file automatically. But you do not know how. What should you do?
Prerequisites
If kubelet, kubeadm and kubectl are installed, skip the prerequisites to go to step #1 in the procedures. Otherwise, run these commands:
cd /tmp
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl
curl -Lo kubeadm https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubeadm && chmod +x kubeadm
curl -Lo kubelet https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubelet && chmod +x kubelet
sudo mv /tmp/kube* /usr/bin
If you are running CentOS/RHEL/Fedora, run this command: sudo yum -y install socat ebltables
Procedures
Run this command: sudo kubeadm init
The above command will create this file; it can be a template for a kubeconfig file: /etc/kubernetes/admin.conf
If you want to create one manually, you may want to see this posting.
Problem scenario
You want to use Molecule to test Ansible roles. How do you install Molecule on Ubuntu 18.x with Python 3?
Solution
Prerequisites
i. You must have Docker installed. If you need assistance see this posting.
ii. You must have pip3 installed on the Docker host. sudo apt-get install -y python3-pip
Procedures
1. Run these commands:
python3 -m pip install virtualenv
python3 -m virtualenv my_env
source my_env/bin/activate
python3 -m pip install molecule docker
molecule init role -r ansible-apache -d docker
cd ansible-apache
molecule test
2.a. Run this command: vi tasks/main.yml
2.b. Delete what is there. Put this there instead:
---
- name: "Ensure required packages are present"
yum:
name: "{{ pkg_list }}"
state: present
- name: "Ensure latest index.html is present"
template:
src: index.html.j2
dest: /var/www/html/index.html
- name: "Ensure httpd service is started and enabled"
service:
name: "{{ item }}"
state: started
enabled: true
with_items: "{{ svc_list }}"
- name: "Whitelist http in firewalld"
firewalld:
service: http
state: enabled
permanent: true
immediate: true
3. Run this command: mkdir templates
4.a. Run this command: vi templates/index.html.j2
4.b. Put these three lines in it and save it:
<div style="text-align: center">
<h2>Managed by Ansible</h2>
</div>
5.a. Run this command: vi vars/main.yml
5.b. Delete what is there. Place this code starting at the first non-blank line:
---
pkg_list:
- httpd
- firewalld
svc_list:
- httpd
- firewalld
6.a. Run this command: vi molecule/default/tests/test_default.py
6.b. Eliminate the content. Place these lines in the place of the old content:
import os
import pytest
import testinfra.utils.ansible_runner
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
@pytest.mark.parametrize('pkg', [
'httpd',
'firewalld'
])
def test_pkg(host, pkg):
package = host.package(pkg)
assert package.is_installed
@pytest.mark.parametrize('svc', [
'httpd',
'firewalld'
])
def test_svc(host, svc):
service = host.service(svc)
assert service.is_running
assert service.is_enabled
@pytest.mark.parametrize('file, content', [
("/etc/firewalld/zones/public.xml", "<service name=\"http\"/>"),
("/var/www/html/index.html", "Managed by Ansible")
])
def test_files(host, file, content):
file = host.file(file)
assert file.exists
assert file.contains(content)
7. Run this: molecule test
8. You are done. The above directions were adapted from a DigitalOcean tutorial here.
Problem scenario
You try to run a kubeadm command. You get an error about kubelet
" [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'"
How do you get "sudo systemctl start kubelet" or "sudo systemctl enable kubelet" to work? How do you create your own kubelet.service file?
Solution
[Unit]
Description=kubelet
[Service]
Type=simple
User=docker
Group=docker
ExecStart=/usr/bin/kubelet
Restart=always
WorkingDirectory=/
Nice=19
[Install]
WantedBy=multi-user.target
3. Now try these commands:
sudo systemctl start kubelet
sudo systemctl enable kubelet
(It may not stay on. But this can work for satisfying certain dependencies for proving experimental concepts. If you want the kubelet service to remain on and you are running a Red Hat derivative of Linux, see this posting.)
Problem scenario
You have some older speakers plugged into your laptop that was recently reformatted (Windows 10 was recently installed). You know the laptop's audio works via its built-in speakers. You know the speakers work from your a second laptop. But one laptop seems not compatible with one pair of head phones or one set of external speakers. There is a 3.5 mm jack that you connect the speakers to your laptop. Everything seems fine, but there is no sound. What should you do?
Solution
See also this posting. As a last resort (if you have a physical hardware problem) you may want to buy new speakers; you can do so here. You can buy a new laptop here.
Problem scenario
You are using an Ansible-supported method of a variable in a playbook. This variable will substitute a string or line number that the playbook is run on with the IP address of the host. You notice that this substitution includes an opening-and-closing single quote mark "'" and a pair of opening-and-closing brackets "[]". That is, single quotes and brackets are being introduced into the string you want to build with the Ansible playbook.
The playbook (aka .yaml file) has lines like these:
vars:
ip_address: "{{ ansible_all_ipv4_addresses }}"
The string that is later being created shows IP addresses like these:
['12.34.56.78']
You want it to be like this: 12.34.56.78
How do you get the playbook to work without adding these quote and bracket characters?
Solution
Rather than use the format (or syntax above), use this format below in your playbook:
vars:
ip_address: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"
YoYou may also want to see How Do You Get an Ansible Variable to Not Add Single Quotes or Brackets when the Variable Is Substituted?.
Problem scenario
You run sonar-scanner, but it fails with an error such as this: "No quality profiles have been found, you probably don't have any language plugin installed."
You run sonar-scanner with the "-X" and see a Java stack trace like this: "Error during SonarQube Scanner execution java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.report.MetadataPublisher"
You log into the SonarQube web UI. You go to "Quality Profiles" but you see no profiles and no button or option to create one.
How do you get sonar-scanner to work?
Solution
1. Go to the server with the sonar-scanner.
2. Find the main sonar directory. One command that should help is this: sudo find / -name sonar -type d
In this directory there should be a directory path such as this: extensions/plugins
3. Go to …/sonar/extensions/plugins/ and place one or more language .jar files so that SonarQube can analyze code of that language. The free Community Edition of SonarQube cannot support certain languages as there are no .jar files for certain languages. But it can support many common, popular, modern languages. To obtain the .jar file for a given language (that is a plugin for SonarQube to have a Quality Profile), go here. You can copy the .jar file to the SonarQube server.