田辺  亮介

田辺 亮介

1659694140

如何使用 GitHub Action 運行 Ansible Playbook?

如何使用 GitHub Action 運行 Ansible Playbook?

從 Github 自動配置

玩完 Ansible並在筆記本電腦上配置東西了嗎?👼

讓我們更上一層樓,利用Github Action為您的劇本創建部署管道。這將大大改善您的工作流程,並確保您所採取的所有步驟都是可重複的。💪

本教程旨在引導您完成設置 Github 操作工作流的步驟,以驗證您的配置並針對您的庫存運行您的劇本。這將使我們能夠設置一個自動化管道,該管道可以由 GitHub 上的提交或拉取請求觸發,並且管理基礎設施的開銷最小。

用於環境配置和部署的 GitHub 和 Terraform

快速提醒

Ansible是一種流行的配置管理工具,用於配置基礎架構的狀態。Ansible Playbook是您希望在服務器上執行以創建所需狀態的一系列任務。playbook 通常會調用模塊,然後執行一個或多個操作,具體取決於我們在其中定義的內容。

GitHub Action是一個內置在 Github 中的自動化工具,用於觸發構建、部署代碼和一般的自動化。Github Action 很好地與 Github 的每個元素交互,例如將提交推送到分支、創建拉取請求、創建問題等。

入門的基本 Ansible 劇本

您可能已經有一本想要自動運行的劇本 🚒,但讓我們從一個 hello-world 劇本開始。創建以下文件,讓我們hello-world.yaml在名為 的文件夾中調用它ansible

- name: This is a hello-world example
  hosts: all
  tasks:
    - name: Create a file called '/tmp/testfile.txt' with the content 'hello world'.
      copy:
        content: hello-world
        dest: /tmp/testfile.txt
        mode: 0644

配置 GitHub Action 以驗證您的 Ansible 代碼

您的劇本已準備就緒,我們需要集成配置工作流程。😄

讓我們創建一個新的 GitHub Action 工作流。轉到操作選項卡並選擇自行設置工作流

在市場中搜索 Ansible。這使得 GitHub Action 如此強大,以至於您總是有幾十個隨時可用的 Actions 觸手可及。👼

讓我們從一些棉絨開始💪。您希望您的 ansible 代碼在將其執行到生產環境之前盡可能好。選擇ansible-lint模塊,因為它是 Ansible Galaxy(官方 Ansible 存儲庫)用於將質量分數歸因於推送到那裡的角色的模塊。因此,ansible-lint 被認為是 Ansible 的默認 linter。

Github Action 的另一個優點是註釋功能。在這種情況下,操作可以非常簡單地註釋您的代碼,您ansible-lint和註釋,只要他對您的代碼不滿意。😄

在這一點上,如果像我一樣,您的項目中有其他劇本,可能會進行一些初步清理。

ansible-lint您可能還需要使用配置文件進行微調。ansible-lint 您可以在此處找到有關配置的更多信息。例如,我忽略了,fqcn-builtins因為它迫使你寫ansible.builtin.copy而不是copy. 在我看來,內置函數應該簡短而美觀,所以這個規則概念讓我很困擾。

# This makes linter to ignore rules/tags listed below fully
skip_list:
  - 'fqcn-builtins'

這是此階段的 Github Action 工作流程。

# This is a basic workflow to help you get started with Actions
name: Ansible Docker Swarm
# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "validate"
  validate:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3
      - name: Run ansible-lint
        # replace `main` with any valid ref, or tags like `v6`
        uses: ansible-community/ansible-lint-action@v6.0.2
        with:
          args: "ansible" # my ansible files in a folder

你完成了 linting 嗎?你所有的代碼都無可挑剔嗎?

使用 Github Action 運行你的劇本。

讓我們回到那個GitHub Action Marketplace來找到你需要的東西。不幸的是,這次沒有簡單靈活的解決方案。

但是,我希望您有這種反應,首先檢查市場並挑戰解決方案。🐒

Ansible 是一個 Python 應用程序🐍,因此我們需要在工作流程中設置 Python 環境。您將創建一個名為run-playbook之後運行的新作業validate(使用該needs屬性)。

run-playbook:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
		# The validate Job need to be sucessfull
		needs: [ validate ]
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3
      - name: Set up Python 3.9
        uses: actions/setup-python@v2
        with:
          python-version: 3.9
      - name: Install dependencies Including Ansible
        run: |
          python -m pip install --upgrade pip
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
          if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi

設置一個🐍ython 環境是非常標準的。您將使用requirements.txt來避免您需要的所有依賴項,包括 Ansible:

ansible==2.10.7
ansible-lint==6.0.2
jsondiff==2.0.0
passlib==1.7.4
PyYAML==6.0

然後你需要一個 Ansible 的清單文件。庫存是敏感信息,所以我使用秘密來存儲我的庫存文件。剩下的就是將秘密的值寫入文件,Ansible 將能夠從中讀取。

- name: write inventory to file
    env:
      INVENTORY: ${{ secrets.INVENTORY }}
    run: 'echo "$INVENTORY" > inventory'

接下來,要與您的服務器通信,您需要 SSH 密鑰對。管理 SSH 密鑰的最佳方法是通過這個ssh-agent. 對我們來說幸運的是,有一個行動可以做到這一點。這裡的所有值都是敏感的,因此它們存儲在秘密中。


- name: Install SSH key
        uses: shimataro/ssh-key-action@v2
        with:
          key: ${{ secrets.SSH_KEY }}
          name: id_rsa # optional
          known_hosts: ${{ secrets.KNOWN_HOSTS }}
          # config: ${{ secrets.CONFIG }} # ssh_config; optional
          if_key_exists: fail # replace / ignore / fail; optional (defaults to fail)

最後一點,運行你的劇本。此步驟很簡單:ansible-playbook使用您的清單文件作為參數運行該命令。


- name: run playbook
    run: |
      ansible-playbook -i inventory ansible/hello-world.yaml

剩下要做的就是運行管道。

最終管道

鏈接:https ://medium.com/faun/how-to-run-an-ansible-playbook-using-github-action-42430dec944

#github #githubaction #playbook

What is GEEK

Buddha Community

如何使用 GitHub Action 運行 Ansible Playbook?
田辺  亮介

田辺 亮介

1659694140

如何使用 GitHub Action 運行 Ansible Playbook?

如何使用 GitHub Action 運行 Ansible Playbook?

從 Github 自動配置

玩完 Ansible並在筆記本電腦上配置東西了嗎?👼

讓我們更上一層樓,利用Github Action為您的劇本創建部署管道。這將大大改善您的工作流程,並確保您所採取的所有步驟都是可重複的。💪

本教程旨在引導您完成設置 Github 操作工作流的步驟,以驗證您的配置並針對您的庫存運行您的劇本。這將使我們能夠設置一個自動化管道,該管道可以由 GitHub 上的提交或拉取請求觸發,並且管理基礎設施的開銷最小。

用於環境配置和部署的 GitHub 和 Terraform

快速提醒

Ansible是一種流行的配置管理工具,用於配置基礎架構的狀態。Ansible Playbook是您希望在服務器上執行以創建所需狀態的一系列任務。playbook 通常會調用模塊,然後執行一個或多個操作,具體取決於我們在其中定義的內容。

GitHub Action是一個內置在 Github 中的自動化工具,用於觸發構建、部署代碼和一般的自動化。Github Action 很好地與 Github 的每個元素交互,例如將提交推送到分支、創建拉取請求、創建問題等。

入門的基本 Ansible 劇本

您可能已經有一本想要自動運行的劇本 🚒,但讓我們從一個 hello-world 劇本開始。創建以下文件,讓我們hello-world.yaml在名為 的文件夾中調用它ansible

- name: This is a hello-world example
  hosts: all
  tasks:
    - name: Create a file called '/tmp/testfile.txt' with the content 'hello world'.
      copy:
        content: hello-world
        dest: /tmp/testfile.txt
        mode: 0644

配置 GitHub Action 以驗證您的 Ansible 代碼

您的劇本已準備就緒,我們需要集成配置工作流程。😄

讓我們創建一個新的 GitHub Action 工作流。轉到操作選項卡並選擇自行設置工作流

在市場中搜索 Ansible。這使得 GitHub Action 如此強大,以至於您總是有幾十個隨時可用的 Actions 觸手可及。👼

讓我們從一些棉絨開始💪。您希望您的 ansible 代碼在將其執行到生產環境之前盡可能好。選擇ansible-lint模塊,因為它是 Ansible Galaxy(官方 Ansible 存儲庫)用於將質量分數歸因於推送到那裡的角色的模塊。因此,ansible-lint 被認為是 Ansible 的默認 linter。

Github Action 的另一個優點是註釋功能。在這種情況下,操作可以非常簡單地註釋您的代碼,您ansible-lint和註釋,只要他對您的代碼不滿意。😄

在這一點上,如果像我一樣,您的項目中有其他劇本,可能會進行一些初步清理。

ansible-lint您可能還需要使用配置文件進行微調。ansible-lint 您可以在此處找到有關配置的更多信息。例如,我忽略了,fqcn-builtins因為它迫使你寫ansible.builtin.copy而不是copy. 在我看來,內置函數應該簡短而美觀,所以這個規則概念讓我很困擾。

# This makes linter to ignore rules/tags listed below fully
skip_list:
  - 'fqcn-builtins'

這是此階段的 Github Action 工作流程。

# This is a basic workflow to help you get started with Actions
name: Ansible Docker Swarm
# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "validate"
  validate:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3
      - name: Run ansible-lint
        # replace `main` with any valid ref, or tags like `v6`
        uses: ansible-community/ansible-lint-action@v6.0.2
        with:
          args: "ansible" # my ansible files in a folder

你完成了 linting 嗎?你所有的代碼都無可挑剔嗎?

使用 Github Action 運行你的劇本。

讓我們回到那個GitHub Action Marketplace來找到你需要的東西。不幸的是,這次沒有簡單靈活的解決方案。

但是,我希望您有這種反應,首先檢查市場並挑戰解決方案。🐒

Ansible 是一個 Python 應用程序🐍,因此我們需要在工作流程中設置 Python 環境。您將創建一個名為run-playbook之後運行的新作業validate(使用該needs屬性)。

run-playbook:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
		# The validate Job need to be sucessfull
		needs: [ validate ]
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v3
      - name: Set up Python 3.9
        uses: actions/setup-python@v2
        with:
          python-version: 3.9
      - name: Install dependencies Including Ansible
        run: |
          python -m pip install --upgrade pip
          if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
          if [ -f test-requirements.txt ]; then pip install -r test-requirements.txt; fi

設置一個🐍ython 環境是非常標準的。您將使用requirements.txt來避免您需要的所有依賴項,包括 Ansible:

ansible==2.10.7
ansible-lint==6.0.2
jsondiff==2.0.0
passlib==1.7.4
PyYAML==6.0

然後你需要一個 Ansible 的清單文件。庫存是敏感信息,所以我使用秘密來存儲我的庫存文件。剩下的就是將秘密的值寫入文件,Ansible 將能夠從中讀取。

- name: write inventory to file
    env:
      INVENTORY: ${{ secrets.INVENTORY }}
    run: 'echo "$INVENTORY" > inventory'

接下來,要與您的服務器通信,您需要 SSH 密鑰對。管理 SSH 密鑰的最佳方法是通過這個ssh-agent. 對我們來說幸運的是,有一個行動可以做到這一點。這裡的所有值都是敏感的,因此它們存儲在秘密中。


- name: Install SSH key
        uses: shimataro/ssh-key-action@v2
        with:
          key: ${{ secrets.SSH_KEY }}
          name: id_rsa # optional
          known_hosts: ${{ secrets.KNOWN_HOSTS }}
          # config: ${{ secrets.CONFIG }} # ssh_config; optional
          if_key_exists: fail # replace / ignore / fail; optional (defaults to fail)

最後一點,運行你的劇本。此步驟很簡單:ansible-playbook使用您的清單文件作為參數運行該命令。


- name: run playbook
    run: |
      ansible-playbook -i inventory ansible/hello-world.yaml

剩下要做的就是運行管道。

最終管道

鏈接:https ://medium.com/faun/how-to-run-an-ansible-playbook-using-github-action-42430dec944

#github #githubaction #playbook

Desmond  Gerber

Desmond Gerber

1624347085

How to Create a Custom GitHub Actions Using JavaScript — Beginner Level

In this blog, we are going to learn how to create our own custom GitHub action using javaScript.

Prerequisite

  • Basic JavaScript Knowledge
  • Basic Git & GitHub Knowledge

About GitHub Actions

Automate, customize, and execute your software development workflows right in your repository with GitHub Actions. You can discover, create, and share actions to perform any job you’d like, including CI/CD, and combine actions in a completely customized workflow.

Types of Actions

There are three types of actions: Docker container actions, JavaScript actions, and composite run steps actions.

JavaScript Custom Action

Let’s create a Custom GitHub Action using JavaScript by creating a public repo, once the repo is created, we can clone it to our local machine using VS Code or GitPod. You need to have Node.js 12.x or higher and npm installed on your machine to perform the steps described here. You can verify the node and npm versions with the following commands in a VS Code or GitPod terminal.

node --version 
npm --version

#github #github-tutorial #github-actions #github-trend

Oral  Brekke

Oral Brekke

1617437520

Deploying my portfolio website on Github Pages using Github Actions.

I recently deployed  my portfolio site and wanted to try out github actions and this is my experience of automating the deployment.

This article is more focused on how you can use the GitHub actions and how easy it is to deploy your code to GitHub pages rather than the portfolio site code.So every time you make an update or build to your website ,the changes are automatically reflected and this automated deploying process makes work much faster.

The way GitHub action works is you create actions in your repositories by creating one or more yaml files and these are called workflows.Workflows now can handle build tasks like CI CD. This means you use the action to test your code and push the site to the desired hosting platform (in this case GitHub pages ) when the main branch changes .

First step assuming that you have a GitHub account is to create a repository having your website code in it.Now I have a bootstrap website but in the future I do plan on adding node JS so I already added package.json.

#workflow #portfolio #github #github-actions #github-pages

Edison  Stark

Edison Stark

1603861600

How to Compare Multiple GitHub Projects with Our GitHub Stats tool

If you have project code hosted on GitHub, chances are you might be interested in checking some numbers and stats such as stars, commits and pull requests.

You might also want to compare some similar projects in terms of the above mentioned stats, for whatever reasons that interest you.

We have the right tool for you: the simple and easy-to-use little tool called GitHub Stats.

Let’s dive right in to what we can get out of it.

Getting started

This interactive tool is really easy to use. Follow the three steps below and you’ll get what you want in real-time:

1. Head to the GitHub repo of the tool

2. Enter as many projects as you need to check on

3. Hit the Update button beside each metric

In this article we are going to compare three most popular machine learning projects for you.

#github #tools #github-statistics-react #github-stats-tool #compare-github-projects #github-projects #software-development #programming

Juana  O'Keefe

Juana O'Keefe

1603830240

A better logs experience with GitHub Actions

It’s now even easier to review logs from your GitHub Actions workflow runs. We’ve introduced several improvements to make the experience more performant, precise, and pleasing to use.

Why these changes matter

When we think about successful automation, we aim to spend the least amount of time looking at what’s automated, so we can focus our attention on what’s relevant. But sometimes things don’t go as planned, and we are required to review what happened. That debugging process can be frustrating; that’s why we’re introducing a series of changes that will improve both performance and user experience:

  • Simplified the layout structure
  • Introduced a single and faster virtualized scrolling
  • The search is now more responsive
  • Better ANSI, 8-bit, and 24-bit color support
  • URLs are now interactive
  • A new full-screen view mode
  • A refreshed UI that improves readability and overall interactions

#features #product #actions #ci/cd #github actions #github