I'm using https://github.com/dawidd6/action-ansible-playbook in my pipeline and I need to somehow install the dependency before even running Ansible on the Github Runner. And that does not seem to work for some reason. Any idea what this could be?
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: build-docker
steps:
- name: Check out the codebase.
uses: actions/checkout#v2
- name: Uses Python 3.11
uses: actions/setup-python#v3
with:
python-version: '3.11.0-alpha.1'
- name: Install Jmespath Dependency
run: |
pip3 install jmespath
pip3 freeze # just to see what is installed
sudo apt install -y python3-jmespath
- name: Run playbook
uses: dawidd6/action-ansible-playbook#v2
with:
playbook: provision_vps.yml
directory: ./ansible
key: ${{secrets.ANSIBLE_PRIVATE_KEY}}
vault_password: ${{secrets.ANSIBLE_VAULT_PASS}}
options: |
--inventory hosts.inventory
--verbose
Note that the indentation above is not correct here, it is fine in my editor. Everything else works fine, it's just that dependency that will not be installed on my GitHub Runner so the Ansible controller can run using this task:
- name: Get all file_sd files from scrape_configs
set_fact:
file_sd_files: "{{ prometheus_scrape_configs | json_query('[*][].file_sd_configs[*][].files[]') }}"
The error message I get is:
fatal: [cache.hugin.chat]: FAILED! => {"msg": "You need to install \"jmespath\" prior to running json_query filter"}
Related
I have added Machine Learning Model and preceding with CI pipeline in Github, however while executing workflow, I am getting error for Missing required root key on. Below is my yml file code.
ci_pipeline:
on:
push:
branches:
- main
steps:
- uses: actions/checkout#v1
with:
fetch-depth: 0
- name: Set up Python 3.9
uses: actions/setup-python#v1
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Format
run: |
black app.py
- name: Lint
run: |
pylint --disable=R,C app.py
- name: Test
run: |
python -m pytest -vv test.py
I started using github actions and I am trying to let a few lines of shell script running before I create a python package. But I can't get my code to run. It always stops on the line run: | - which is odd because I have been using this exact line before before (see further down). Does anyone know what I am doing wrong?
name: Python packaging
on: [push]
jobs:
job1:
name: Update version
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout#v3
# ----- This is where the error occurs. Error message:
# Check failure on line 11 in .github/workflows/main.yml
# GitHub Actions / .github/workflows/main.yml
# Invalid workflow file
# You have an error in your yaml syntax on line 11
- name: Increase version
run: |
old_version=$(grep -oP '(?<=0.0.)[0-99]+' contrib/_version.py)
new_version=$(($old_version + 1))
str="__version__=\"0.0."
out="$str$new_version\""
sed -i '1s/.*/'$out'/' contrib/_version.py
job2:
name: Build and upload
needs: job1
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9"]
steps:
- name: checkout repo
uses: actions/checkout#v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python#v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install setuptools wheel
python -m pip install --upgrade build
python -m pip install --upgrade twine
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Create package
run: |
python3 -m build
- name: Upload to Test PyPI
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
TWINE_REPOSITORY_URL: "https://test.pypi.org/legacy/"
run: |
twine check dist/*
twine upload --verbose --skip-existing dist/*
The file is in YAML syntax which highly depends on indentation.
Based on your example:
job1: and job2: must have the same indentation.
Under steps:, name: and uses: must have the same indentation.
...
name: Python packaging
on: [push]
jobs:
job1:
name: Update version
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout#v3
- name: Increase version
run: |
old_version=$(grep -oP '(?<=0.0.)[0-99]+' contrib/_version.py)
new_version=$(($old_version + 1))
str="__version__=\"0.0."
out="$str$new_version\""
sed -i '1s/.*/'$out'/' contrib/_version.py
job2:
name: Build and upload
# ...
I was trying to understand the CI/CD flow from this tutorial by Indian Pythonista and after following the tutorial and setting the Heroku app name and token in the Github Secrets I ran the yaml file below.
name: Python application
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- run: |
git fetch --prune --unshallow
- name: Set up Python 3.8
uses: actions/setup-python#v1
with:
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pip install pytest
export PYTHONPATH=src
pytest
- name: Deploy to Heroku
env:
HEROKU_API_TOKEN: ${{ secrets.HEROKU_API_TOKEN }}
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_LINKNAME }}
if: github.ref == 'refs/heads/master' && job.status == 'success'
run: |
git remote add heroku https://heroku:$HEROKU_API_TOKEN#git.heroku.com/$HEROKU_APP_NAME.git
git push heroku HEAD:master -f
The build looked like the screenshot below:
I do not exactly know what should I call this error as well, since I am new to the topic. Due to this, the flask app doesn't get updated on the Heroku app link as well.
I need to use with_items loop to install apache2, sqlite3, and git in Ansible. I'm trying to use the below code but it seems like nothing is happening.
---
- hosts: all
sudo: yes
name: install apache2, sqlite3, git on remote server
tasks:
- name: Install list of packages
action: apt pkg={{item}} state=installed
with_items:
- apache2
- sqlite3
- git
you have to place the variable item inside the double quotes...
Try this code it'll work:
---
- name: install apache2, sqlite3, git on remote servers
hosts: all
become: true
tasks:
- name: Install packages
package:
name: "{{item}}"
state: present
loop:
- apache2
- sqlite3
- git
Try
---
- name: install apache2, sqlite3, git on remote servers
hosts: all
sudo: true
tasks:
- name: Install packages
package:
name: {{ item }}
state: present
loop:
- apache2
- sqlite3
- git
See package – Generic OS package manager
"This module actually calls the pertinent package modules for each system (apt, yum, etc)."
See apt – Manages apt-packages if you need apt specific attributes.
I would like to install the base CentOS to a specify directory, example to /var/centos. The directory is empty. I usage the next command in yum:
yum --disablerepo='*' --enablerepo='base,updates' --releasever=7 --installroot=/var/centos groupinstall #core
This command installs the base system without any problems. I want to do the same through Ansible.
In Ansible I usage the next task:
- name: Install base CentOS
yum:
state: latest
name: "#core"
installroot: "/var/centos/"
disablerepo: "*"
enablerepo: "base,updates"
releasever: "7"
When executing a playbook I receive an error:
Cannot find a valid baseurl for repo: base/$releasever/x86_64
As I understand, the yum don't see any repo.
I make list:
- name: Install base CentOS
yum:
list: repos
installroot: "/var/centos/"
When I execute the task I receive nothing.
Why doesn't yum module see repos?
Updated.
Before performing the Install base task, I executed the command - rpm --root /var/centos --force --nodeps -ivh http://mirror.centos.org/centos/7/os/x86_64/Packages/centos-release-7-6.1810.2.el7.centos.x86_64.rpm, after that everything worked.
The final playbook:
vars:
root_path: "/var/centos/"
tasks:
- name: Install package centos-release-7-6.1810.2.el7.centos.x86_64.rpm
shell: rpm --root {{ root_path }} --force --nodeps -ivh http://mirror.centos.org/centos/7/os/x86_64/Packages/centos-release-7-6.1810.2.el7.centos.x86_64.rpm
- name: Install base CentOS
yum:
state: installed
name:
- "#core"
installroot: "{{ root_path }}"
disablerepo: "*"
enablerepo: "base,updates"
releasever: "7"