How to Dry Run Ansible Playbook

I have test.yaml playbook with the following content.

- name: My playbook
  hosts: all
  tasks:
     - name: Leaving a mark
       command: "touch /tmp/ansible_was_here"

I would like to do dry run using this playbook. Here is what I can do.

ansible-playbook-3 test.yaml --check

Here is the output.

[opc@ansible-primary ansible]$ ansible-playbook-3 test.yaml --check

PLAY [My playbook] *******************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************
[WARNING]: Platform linux on host jenkins.pub.ashburn.oraclevcn.com is using the discovered Python interpreter at /usr/bin/python, but future
installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
ok: [jenkins.pub.ashburn.oraclevcn.com]
ok: [ansibletest.westcentralus.cloudapp.azure.com]

TASK [Leaving a mark] ****************************************************************************************************************************
skipping: [jenkins.pub.ashburn.oraclevcn.com]
skipping: [ansibletest.westcentralus.cloudapp.azure.com]

PLAY RECAP ***************************************************************************************************************************************
ansibletest.westcentralus.cloudapp.azure.com : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0
jenkins.pub.ashburn.oraclevcn.com : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

It skipped the actual execution on the hosts specified in /etc/ansbile/hosts and returned ok for each host.

Managed Node in Azure

I provisioned a Red Hat Linux in Azure. When you provision a Linux host in Azure, the default user is azureuser. I would like to manage the host from the Ansible node on OCI. Here is the /etc/ansible/hosts file that I modified.

[jenkins]
jenkins.pub.ashburn.oraclevcn.com

[test]
ansibletest.westcentralus.cloudapp.azure.com

When I test the managed nodes, I get the following error.

ansibletest.westcentralus.cloudapp.azure.com | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).",
    "unreachable": true
}

This is because Ansible tries to access the host with the default user instead of azureuser. To specify a certain user to be used on the managed node, here is what you can do.

[jenkins]
jenkins.pub.ashburn.oraclevcn.com

[test]
ansibletest.westcentralus.cloudapp.azure.com ansible_user=azureuser

If you run the following commnad…

ansible-3 all -m ping

Output:

jenkins.pub.ashburn.oraclevcn.com | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
ansibletest.westcentralus.cloudapp.azure.com | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}

This way, it uses azureuser to access the host in Azure.

Getting Started with Ansible

Why Ansible?

If you have tens, hundreds or thousands of servers, you will need a solution like Ansible or Puppet. These products allow you to define how each server is configured in declarative languages and they can control thousands of servers.

Starting with Ansible

I provisioned an ARM64 host for Ansible yesterday. I wrote an article that explains how to install Ansible on it here. Now I want to test it.

So the Ansible host has to know about Jenkins host. I have added the following lines in /etc/ansible/hosts file.

[jenkins]
jenkins.pub.ashburn.oraclevcn.com

The hosts file can have IP address or FQDN, so I added the FQDN on OCI.

Now I should be able to ssh into the Jenkins host from Ansible host, so I added the public key of Ansible to Jenkins’ authorized_keys. Now I can ssh into the Jenkins host from the Ansible host.

On the Ansible host, test the configuration.

ansible-3 all -m ping

Output:

jenkins.pub.ashburn.oraclevcn.com | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}

Test running a command on the client host.

ansible all -a "/bin/echo hello"

Output:

jenkins.pub.ashburn.oraclevcn.com | CHANGED | rc=0 >>
hello

Creating a Playbook

I am creating the following file jenkins_playbook.yaml with the content below.

- name: Jenkins Playbook
  hosts: all
  tasks:
    - name: Create a file
      shell: |
       echo 'hoge hoge hoge' >> ~/test.txt

Execute the playbook.

ansible-playbook-3 jenkins_playbook.yaml

Output:

PLAY [Jenkins Playbook] **************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************
[WARNING]: Platform linux on host jenkins.pub.ashburn.oraclevcn.com is using the discovered Python interpreter at /usr/bin/python, but future
installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
ok: [jenkins.pub.ashburn.oraclevcn.com]

TASK [Create a file] *****************************************************************************************************************************
changed: [jenkins.pub.ashburn.oraclevcn.com]

PLAY RECAP ***************************************************************************************************************************************
jenkins.pub.ashburn.oraclevcn.com : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

We’ll ignore the warning for now. Now I am going to ssh into the Jenkins host and check the ~/test.txt file.

[opc@jenkins ~]$ cat test.txt
hoge hoge hoge

This concludes the very basics of how Ansible works. I am planning to dig into it more as I have time during the end of year holidays.

How to List Listening Ports on Linux

When you start daemons or Docker containers that listen to certain ports, you want to make sure they are actually listening. You can use netstat to list listening ports.

netstat -tulpn

As you can see, we can’t tell the process or process ID for each port. If you just add sudo, you can see the process information.

This is an essential tool when you diagnose what’s going on on the host where you want to host daemons/services.

2021 at a Glance

I have been blogging since June 2018. This year has been rocky in my personal life (health wise) but I accomplished something great in this space. I have taken full control over my blog engine and DNS by moving my domain name to DNSimple and by provisioning WordPress engine on Docker on OCI. That was some struggle but it was totally worth it for me because I’ve got to learn so much from it.

After all I am a software engineer and I should be able to do it but if you don’t try to dig into it, I would never have accomplished it. This blog is hosted in OCI where the ARM64 host is free of charge, so I am only spending the money for the DNSimple service which is about $60 annually. $60 for your own domain and a free hosting for your blog site is totally worth it if you don’t mind spending some hours to get it up and running.

My passion is in automation, so I will blog my findings in that area in the next year or whatever is related to software engineering. This is my space after all. Thank you for the all visitors and the ones who left comments in this site.

I look forward to interacting with more people next year.

How to Install Ansible on Oracle Linux 7 on ARM64

I’m wanting to learn Ansible and I would like to get my hands on it, so I am installing Ansible on an ARM64 host on Oracle Cloud Infrastructure.

  • Install Epel Release.
    sudo yum-config-manager --enable ol7_developer_EPEL
  • Install Ansible.
    sudo yum install ansible-python3
  • Check the installation.
    ansible-playbook-3 --version

It worked on Oracle Linux 7 on ARM64. I will blog more about how Ansible works in the coming days.

Migrated to ARM64 Oracle Linux 7

I have migrated my site to Oracle Linux 7 on ARM64 just because I was curious how it would work on ARM64 or if it would work on ARM64 at all.

As of this writing, I’ve got this WordPress site on Docker to work on Oracle Linux 7 on ARM64 processor. It was some struggle but I feel it’s snappier.

Here is the Docker Compose file that works for this site. As you can see, I commented out the mysql image and using Maria DB for ARM64 instead. Maria DB is a fork for MySQL, so it’s sufficient enough for my personal blog site.

version: "3.9"
services:
  db:
    image: arm64v8/mariadb # mysql/mysql-server:8.0.20-aarch64
    volumes:
      - ./mysql:/var/lib/mysql
    restart: always
    command: mysqld --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: YourPassword
      MYSQL_DATABASE: hayato_iriumi_db
      MYSQL_USER: blog_admin
      MYSQL_PASSWORD: AnotherPassword
    networks:
      proxynet:
  phpmyadmin:
    depends_on:
      - db
    image: arm64v8/phpmyadmin
    restart: always
    ports:
      - '8080:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: YourPassword
    networks:
      proxynet:
  wordpress:
    image: arm64v8/wordpress
    container_name: wordpress
    depends_on:
      - db
        # ports:
        # - "8000:80"
    restart: always
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: blog_admin
      WORDPRESS_DB_PASSWORD: AnotherPassword
      WORDPRESS_DB_NAME: hayato_iriumi_db
      WORDPRESS_DEBUG: 'true'
    volumes:
      - ./html:/var/www/html
      - ./wp-content:/var/www/html/wp-content
    networks:
      proxynet:
  reverse:
    image: arm64v8/nginx
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/conf.d:/etc/nginx/conf.d
    ports:
      - "80:80"
      - "443:443"
    restart: always
    networks:
      proxynet:
volumes:
  db_data: {}
  wordpress: {}
networks:
  proxynet:

Docker Compose 2 works well on ARM64 as well. It is definitely faster than Docker Compose 1. By just changing the platform, I feel I upgraded my blog site for a better performance.

WordPress Site on ARM64 Linux

I struggled with provisioning MySQL 8 Docker container for ARM64 today. I just could not access MySQL instance from MyPHPAdmin. I eventually ended up with provisioning Maria DB for ARM64 and now I am able to access it from MyPHPAdmin.

I will spend my time later to migrate my WordPress to the new instance. I believe it will be snappier when it’s done.

How to Install Docker Compose 2 on ARM Processor Linux Host (OL7)

I have provisioned Oracle Linux 7 on ARM processor on OCI. In an attempt to get my blog site to work on the host, I have installed Docker engine and now I want to install Docker Compose 2. Here are the steps.

  1. Create a directory.
    mkdir -p ~/.docker/cli-plugins/
  2. Download the Docker Compose 2 binary for ARM64.
    curl -SL https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-linux-armv7 -o ~/.docker/cli-plugins/docker-compose
  3. Give the binary file execute permission.
    chmod +x ~/.docker/cli-plugins/docker-compose
  4. Check if the binary has been installed successfully.
    docker compose version