From f466fca3e65f5bd4708d9588efd0e183d3606219 Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Wed, 7 Aug 2024 22:27:31 +0200 Subject: [PATCH] chore(ansible): improve notes for awx setup on eks --- knowledge base/ansible.md | 106 +++++++++++++++++++ knowledge base/awx.md | 2 +- knowledge base/cloud computing/aws/README.md | 90 ++++++++++++++++ knowledge base/cloud computing/aws/eks.md | 19 +++- knowledge base/slack.md | 2 + snippets/ansible/tasks.yml | 25 ++++- snippets/aws/commands.fish | 2 + 7 files changed, 241 insertions(+), 5 deletions(-) diff --git a/knowledge base/ansible.md b/knowledge base/ansible.md index b857aad..ccd267d 100644 --- a/knowledge base/ansible.md +++ b/knowledge base/ansible.md @@ -18,6 +18,7 @@ 1. [Assign roles](#assign-roles) 1. [Role dependencies](#role-dependencies) 1. [Create custom filter plugins](#create-custom-filter-plugins) +1. [Execution environments](#execution-environments) 1. [Troubleshooting](#troubleshooting) 1. [Print all known variables](#print-all-known-variables) 1. [Force notified handlers to run at a specific point](#force-notified-handlers-to-run-at-a-specific-point) @@ -555,6 +556,107 @@ collections: See [Creating your own Ansible filter plugins]. +## Execution environments + +Container images that can be used as Ansible control nodes. + +Ansible Builder aids in the creation of Ansible Execution Environments.
+Refer [Introduction to Ansible Builder] for how to build one. + +Builders' `build` command defaults to using: + +- `execution-environment.yml` or `execution-environment.yaml` as the definition file. +- `$PWD/context` as the directory to use for the build context. + +
+ execution-environment.yml example + +Refer [Execution environment definition]. + +```yaml +--- +version: 3 + +build_arg_defaults: + ANSIBLE_GALAXY_CLI_COLLECTION_OPTS: '--pre' + +dependencies: + ansible_core: + package_pip: ansible-core==2.14.4 + ansible_runner: + package_pip: ansible-runner + galaxy: requirements.yml + python: + - six + - psutil + system: bindep.txt + exclude: + python: + - docker + system: + - python3-Cython + +images: + base_image: + name: docker.io/redhat/ubi9:latest + # Other available base images: + # - quay.io/rockylinux/rockylinux:9 + # - quay.io/centos/centos:stream9 + # - registry.fedoraproject.org/fedora:38 + # - registry.redhat.io/ansible-automation-platform-23/ee-minimal-rhel8:latest + # (needs an account) + +# Custom package manager path for the RHEL based images +# options: +# package_manager_path: /usr/bin/microdnf + +additional_build_files: + - src: files/ansible.cfg + dest: configs + +additional_build_steps: + prepend_base: + - RUN echo This is a prepend base command! + # Enable Non-default stream before packages provided by it can be installed. (optional) + # - RUN $PKGMGR module enable postgresql:15 -y + # - RUN $PKGMGR install -y postgresql + prepend_galaxy: + - COPY _build/configs/ansible.cfg /etc/ansible/ansible.cfg + + prepend_final: | + RUN whoami + RUN cat /etc/os-release + append_final: + - RUN echo This is a post-install command! + - RUN ls -la /etc +``` + +
+ +
+ requirements.yml example + +```yaml +--- +collections: + - redhat.openshift +``` + +
+ +
+ Commands example + +```sh +pip install 'ansible-builder' +ansible-builder build --container-runtime 'docker' -t 'example-ee:latest' -f 'definition.yml' +ansible-runner -p 'test_play.yml' --container-image 'example-ee:latest' +ansible-navigator run 'test_play.yml' -i 'localhost,' --execution-environment-image 'example-ee:latest' \ + --mode 'stdout' --pull-policy 'missing' --container-options='--user=0' +``` + +
+ ## Troubleshooting ### Print all known variables @@ -865,6 +967,7 @@ Solution: use a version of `ansible-core` lower than 2.17. - [Mitogen for Ansible] - [Debugging tasks] - [AWX] +- [Introduction to Ansible Builder] ### Sources @@ -901,6 +1004,7 @@ Solution: use a version of `ansible-core` lower than 2.17. - [Looping over lists inside of a dict] - [Newer versions of Ansible don't work with RHEL 8] - [Running your Ansible playbooks in parallel and other strategies] +- [Execution environment definition] ## Requirements @@ -1089,7 +1098,7 @@ Requirements: Specifically, subnets must have the specific, appropriate tags.
Those are actively looked for by the controller, and will miserably fail if they are not present. -Procedure: +Installation: 1. Create a IAM policy using the `/docs/install/iam_policy.json` file in the [controller's repository][aws load balancer controller repository]. @@ -1125,6 +1134,9 @@ Procedure: +Ingresses annotations will configure the load balancers they create.
+Refer [Ingress annotations][aws load balancer controller ingress annotations] for the full list. + ### EBS CSI driver #### EBS CSI driver as aws-managed add-on @@ -1432,6 +1444,7 @@ helm upgrade -i --repo 'https://aws.github.io/eks-charts' \ [amazon elastic block store (ebs) csi driver]: https://github.com/kubernetes-sigs/aws-ebs-csi-driver/blob/master/README.md +[aws load balancer controller ingress annotations]: https://github.com/kubernetes-sigs/aws-load-balancer-controller/blob/main/docs/guide/ingress/annotations.md [aws load balancer controller repository]: https://github.com/kubernetes-sigs/aws-load-balancer-controller [enable ebs gp3 for eks by default]: https://geko.cloud/en/aws-enable-ebs-gp3-for-eks-by-default/ [external-snapshotter]: https://github.com/kubernetes-csi/external-snapshotter diff --git a/knowledge base/slack.md b/knowledge base/slack.md index 178b6fd..0cda7a6 100644 --- a/knowledge base/slack.md +++ b/knowledge base/slack.md @@ -65,6 +65,7 @@ Check out [slackmojis] for some common reactions. ### Sources - [Slackmojis] +- [Slack Notifications for Ansible Tower (AWX)] +[slack notifications for ansible tower (awx)]: https://mpolinowski.github.io/docs/DevOps/Ansible/2021-04-30-ansible-tower-slack-notifications/2021-04-30/ [slackmojis]: https://slackmojis.com/ diff --git a/snippets/ansible/tasks.yml b/snippets/ansible/tasks.yml index 7ca3a34..2eeb99c 100644 --- a/snippets/ansible/tasks.yml +++ b/snippets/ansible/tasks.yml @@ -189,6 +189,15 @@ - name: Manipulate dictionaries block: + - name: Add keys to dictionaries + set_fact: + organization: "{{ organization | combine({ 'name': 'ExampleOrg' }) }}" + - name: Sort keys in dictionaries + set_fact: + organization: "{{ organization | dictsort }}" + - name: Pretty print dictionaries + set_fact: + organization: "{{ organization | to_nice_json }}" - name: Merge dictionaries vars: dict_1: @@ -215,7 +224,7 @@ }) }} with_items: "{{ db_extensions_query.results }}" - - name: + - name: FIXME vars: db_extensions: sales: @@ -418,3 +427,17 @@ text: type: mrkdwn text: This is a *_fancy_* message + +- name: AWX + environment: + CONTROLLER_HOST: https://awx.example.org/ + CONTROLLER_VERIFY_SSL: false + CONTROLLER_USERNAME: admin + CONTROLLER_PASSWORD: somethingSecret + block: + - name: Export all data from existing instances + # At the time of writing: applications, credential_types, credentials, execution_environments, inventory, + # inventory_sources, job_templates, notification_templates, organizations, projects, schedules, teams, and users. + awx.awx.export: + all: true + register: awx_export_output diff --git a/snippets/aws/commands.fish b/snippets/aws/commands.fish index 21c189f..5779dc4 100644 --- a/snippets/aws/commands.fish +++ b/snippets/aws/commands.fish @@ -125,7 +125,9 @@ aws kms decrypt --ciphertext-blob 'fileb://ciphertext.dat' aws kms decrypt --ciphertext-blob 'fileb://ciphertext.dat' --query 'Plaintext' --output 'text' \ | base64 --decode +aws eks --region 'eu-west-1' update-kubeconfig --name 'oneForAll' aws eks --region 'eu-west-1' update-kubeconfig --name 'oneForAll' --profile 'dev-user' +aws eks --region 'eu-west-1' update-kubeconfig --name 'oneForAll' --role-arn 'arn:aws:iam::012345678901:role/AssumedRole' # Create OIDC providers for EKS clusters # 1. Get the OIDC issuer ID for existing EKS clusters