Skip to content

Commit

Permalink
rewrite in javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidd6 committed May 3, 2020
1 parent 47f48fd commit fd56a2a
Show file tree
Hide file tree
Showing 37 changed files with 2,298 additions and 120 deletions.
44 changes: 22 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,26 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Test remote
- name: Setup remote
run: |
docker build -t host -f Dockerfile.test .
docker build -t action -f Dockerfile .
docker run -d \
--name host \
-e SSH_PUBLIC_KEY="${{secrets.SSH_PUBLIC_KEY}}" \
host
docker run -t \
--name action \
--link host \
-v $PWD:/wd \
-w /wd \
-e INPUT_PLAYBOOK="playbook.yml" \
-e INPUT_DIRECTORY="./" \
-e INPUT_KEY="${{secrets.SSH_PRIVATE_KEY}}" \
-e INPUT_OPTIONS="--inventory hosts --limit remote" \
action
echo "${{secrets.SSH_PUBLIC_KEY}}" | sudo tee /etc/ssh/authorized_keys
sudo tee /etc/ssh/sshd_config <<EOF
PasswordAuthentication no
PubkeyAuthentication yes
AuthorizedKeysFile /etc/ssh/authorized_keys
PermitRootLogin no
Subsystem sftp /usr/lib/openssh/sftp-server
EOF
sudo systemctl restart sshd
- name: Test remote
uses: ./
with:
playbook: playbook.yml
directory: ./
key: ${{secrets.SSH_PRIVATE_KEY}}
inventory: |
[all]
localhost
test-local:
runs-on: ubuntu-latest
steps:
Expand All @@ -35,10 +37,9 @@ jobs:
uses: ./
with:
playbook: playbook.yml
key: ${{secrets.SSH_PRIVATE_KEY}}
options: |
--inventory hosts
--limit local
--inventory hosts
--limit local
test-local-more:
runs-on: ubuntu-latest
steps:
Expand All @@ -48,11 +49,10 @@ jobs:
uses: ./
with:
playbook: playbook.yml
key: ${{secrets.SSH_PRIVATE_KEY}}
vault_password: test
inventory: |
[all]
localhost ansible_user=root ansible_connection=local
localhost ansible_connection=local
options: |
-e key1=val1
-e key2=val2
7 changes: 0 additions & 7 deletions Dockerfile

This file was deleted.

17 changes: 0 additions & 17 deletions Dockerfile.test

This file was deleted.

6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ inputs:
required: false
key:
description: SSH private key used to connect to the host
required: true
required: false
inventory:
description: Custom content to write into hosts
required: false
Expand All @@ -23,5 +23,5 @@ inputs:
description: Extra options that should be passed to ansible-playbook command
required: false
runs:
using: docker
image: Dockerfile
using: node12
main: main.js
5 changes: 1 addition & 4 deletions hosts
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
[remote]
host ansible_user=user

[local]
localhost ansible_user=root ansible_connection=local
localhost ansible_connection=local
56 changes: 56 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const core = require('@actions/core')
const exec = require('@actions/exec')
const fs = require('fs')
const os = require('os')
const path = require('path')

async function main() {
try {
const playbook = core.getInput("playbook", { required: true })
const directory = core.getInput("directory")
const key = core.getInput("key")
const inventory = core.getInput("inventory")
const vaultPassword = core.getInput("vault_password")
const options = core.getInput("options")

let cmd = ["ansible-playbook", playbook]

if (options) {
cmd.push(options.replace("\n", " "))
}

if (directory) {
process.chdir(directory)
}

if (key) {
const keyFile = ".ansible_key"
fs.writeFileSync(keyFile, key + os.EOL, { mode: 0600 })
cmd.push("--key-file")
cmd.push(keyFile)
}

if (inventory) {
const inventoryFile = ".ansible_inventory"
fs.writeFileSync(inventoryFile, inventory, { mode: 0600 })
cmd.push("--inventory-file")
cmd.push(inventoryFile)
}

if (vaultPassword) {
const vaultPasswordFile = ".ansible_vault_password"
fs.writeFileSync(vaultPasswordFile, vaultPassword, { mode: 0600 })
cmd.push("--vault-password-file")
cmd.push(vaultPasswordFile)
}

process.env.ANSIBLE_HOST_KEY_CHECKING = "False"
process.env.ANSIBLE_FORCE_COLOR = "True"

await exec.exec(cmd.join(" "))
} catch (error) {
core.setFailed(error.message)
}
}

main()
55 changes: 0 additions & 55 deletions main.sh

This file was deleted.

146 changes: 146 additions & 0 deletions node_modules/@actions/core/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions node_modules/@actions/core/lib/command.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fd56a2a

Please sign in to comment.