Skip to content

Instantly share code, notes, and snippets.

@itdependsnetworks
Created April 2, 2024 02:25
Show Gist options
  • Save itdependsnetworks/53987e3c6c820c3111e408b9ad1a9898 to your computer and use it in GitHub Desktop.
Save itdependsnetworks/53987e3c6c820c3111e408b9ad1a9898 to your computer and use it in GitHub Desktop.
Local AWX-EE
password: !vault |
$ANSIBLE_VAULT;1.1;AES256
61363732366665663763656465386566336161383135323766393034393765643734363431333930
6664373330623639363864393230373435663737343639340a393561363334343833653566666562
31363939383762316132363039353739613534356438303765316662373133626333343330633462
3464633761363437340a346338623164393166373162356337623066653931656334313862363739
3432
# Use Red Hat Universal Base Image (UBI)
FROM quay.io/ansible/ansible-runner:latest
# Install necessary packages (customize as needed)
# For a full AWX EE experience, you might need to add more packages or python dependencies
RUN pip install netutils
# Copy your playbook directory into the container
# Assume your local playbook directory is named 'playbooks/'
#COPY playbooks/ /playbooks
# Set working directory to where playbooks are copied
WORKDIR /local
- name: Echo
hosts: local
connection: local
tasks:
- name: Print debug message
debug:
var: password
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee % invoke build
Traceback (most recent call last):
File "/Users/kennethcelenza/Library/Python/3.9/bin/invoke", line 8, in <module>
sys.exit(program.run())
File "/Users/kennethcelenza/Library/Python/3.9/lib/python/site-packages/invoke/program.py", line 373, in run
self.parse_collection()
File "/Users/kennethcelenza/Library/Python/3.9/lib/python/site-packages/invoke/program.py", line 465, in parse_collection
self.load_collection()
File "/Users/kennethcelenza/Library/Python/3.9/lib/python/site-packages/invoke/program.py", line 699, in load_collection
module, parent = loader.load(coll_name)
File "/Users/kennethcelenza/Library/Python/3.9/lib/python/site-packages/invoke/loader.py", line 76, in load
module = imp.load_module(name, fd, path, desc)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/imp.py", line 171, in load_source
module = _load(spec)
File "<frozen importlib._bootstrap>", line 711, in _load
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 850, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/private/tmp/test-awx-ee/tasks.py", line 12, in <module>
raise("Please set the environment variable `IMAGE_NAME` to something unique before running an invoke task.")
TypeError: exceptions must derive from BaseException
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee %
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee %
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee % ########## DID NOT SET IMAGE_NAME SO FAILED
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee %
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee %
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee % export IMAGE_NAME=ken
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee % invoke build
Building image ken:1.0
#0 building with "desktop-linux" instance using docker driver
#1 [internal] load build definition from Dockerfile
#1 transferring dockerfile: 502B 0.0s done
#1 DONE 0.1s
#2 [internal] load .dockerignore
#2 transferring context: 2B done
#2 DONE 0.0s
#3 [internal] load metadata for quay.io/ansible/ansible-runner:latest
#3 DONE 0.3s
#4 [1/3] FROM quay.io/ansible/ansible-runner:latest@sha256:001a4bde411be863d54c1d293f3d2e7b0ff0e67ef5d7b2f9f7fb56b61694f4e8
#4 DONE 0.0s
#5 [2/3] RUN pip install netutils
#5 CACHED
#6 [3/3] WORKDIR /local
#6 CACHED
#7 exporting to image
#7 exporting layers done
#7 writing image sha256:54a38d29ae8014fda4e1eea738c48f2e42b089224450000da02cd1d69aac14fa done
#7 naming to docker.io/library/ken:1.0 done
#7 DONE 0.0s
What's Next?
View summary of image vulnerabilities and recommendations → docker scout quickview
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee %
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee %
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee %
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee %
kennethcelenza@Kenneths-MBP /tmp/test-awx-ee % invoke cli
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
bash-4.4#
bash-4.4#
bash-4.4# ###### CREATE A VAULT VARIABLE
bash-4.4#
bash-4.4#
bash-4.4# ansible-vault encrypt_string my_super_secret --ask-vault-pass
New Vault password:
Confirm New Vault password:
!vault |
$ANSIBLE_VAULT;1.1;AES256
61363732366665663763656465386566336161383135323766393034393765643734363431333930
6664373330623639363864393230373435663737343639340a393561363334343833653566666562
31363939383762316132363039353739613534356438303765316662373133626333343330633462
3464633761363437340a346338623164393166373162356337623066653931656334313862363739
3432
Encryption successful
bash-4.4#
bash-4.4#
bash-4.4#
bash-4.4# ###### COPY THIS INTO .my_vault.yml, as shown in the example
bash-4.4#
bash-4.4#
bash-4.4#
bash-4.4#
bash-4.4# ansible-playbook -i local, --extra-vars "@.my_vault.yml" --ask-vault-pass my-playbook.yml
Vault password:
PLAY [Echo] *************************************************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] **************************************************************************************************************************************************************************************************************************************
ok: [local]
TASK [Print debug message] **********************************************************************************************************************************************************************************************************************************
ok: [local] => {
"password": "my_super_secret"
}
PLAY RECAP **************************************************************************************************************************************************************************************************************************************************
local : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
bash-4.4#
import os
from invoke import task
PWD = os.getcwd()
IMAGE_NAME = os.getenv("IMAGE_NAME")
IMAGE_VER = os.getenv("IMAGE_VER", "1.0")
if not IMAGE_NAME:
raise("Please set the environment variable `IMAGE_NAME` to something unique before running an invoke task.")
@task
def build(context, nocache=False, forcerm=False, hide=False): # pylint: disable=too-many-arguments
"""Build a Docker image.
Args:
context (obj): Used to run specific commands
nocache (bool): Do not use cache when building the image
forcerm (bool): Always remove intermediate containers
hide (bool): Hide output of Docker image build
"""
print(f"Building image {IMAGE_NAME}:{IMAGE_VER}")
command = f"docker build --tag {IMAGE_NAME}:{IMAGE_VER} -f Dockerfile ."
if nocache:
command += " --no-cache"
if forcerm:
command += " --force-rm"
result = context.run(command, hide=hide)
if result.exited != 0:
print(f"Failed to build image {IMAGE_NAME}:{IMAGE_VER}\nError: {result.stderr}")
@task
def cli(context):
"""Enter the image to perform troubleshooting or dev work.
Args:
context (obj): Used to run specific commands
"""
dev = f"docker run -it --rm --name {IMAGE_NAME}-{IMAGE_VER} -v {PWD}:/local {IMAGE_NAME}:{IMAGE_VER} /bin/bash"
context.run(f"{dev}", pty=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment