---
- name: install apache2, sqlite3, git pn remote server
hosts: host01
sudo: yes
tasks:
- name: Install list of packages
action: apt pkg={{item}} state=installed
with_items:
- apache2
- sqlite3
- git
INVENTORY FILE NAME: myhosts
$cat myhosts
[group1]
host01 ansible_ssh_user=ubuntu
COMMAND USED: ansible-playbook -i myhosts test.yml
ERROR is below one, I don't know what went wrong someone help me in this.
ERROR: Syntax Error while loading YAML script, test.yml
Note: The error may actually appear before this position: line 7, column 12
- name: Install list of packages
action: apt pkg={{item}} state=installed
^
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
Indendation seems wrong at it should be two spaces character by level so try with something like this regarding indentation issue.
---
- name: install apache2, sqlite3, git pn remote server
hosts: host01
sudo: yes
tasks:
- name: Install list of packages
action: apt pkg={{item}} state=installed
with_items:
- apache2
- sqlite3
- git
---
- hosts: all
become: yes
name: install apache2, sqlite3, git pn remote server
tasks:
- name: Install list of packages
action: apt pkg={{item}} state=installed
with_items:
- apache2
- sqlite3
- git
this works for me...
Given command as
---
- name: install apache2, sqlite3, git pn remote server
hosts: host01
become: yes
tasks:
- name: Install list of packages
action: apt pkg={{item}} state=installed
with_items:
- apache2
- sqlite3
- git
below error
ansible-playbook -i myhosts test.yml -b
PLAY [install apache2, sqlite3, git pn remote server] *************************
GATHERING FACTS ***************************************************************
fatal: [host01] => SSH Error: ssh: connect to host host01 port 22: Connection refused
while connecting to 172.17.3.177:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.
TASK: [Install list of packages] **********************************************
FATAL: no hosts matched or all hosts have already failed -- aborting
PLAY RECAP ********************************************************************
to retry, use: --limit #/home/scrapbook/test.retry
host01 : ok=0 changed=0 unreachable=1 failed=0
Related
Problem
$ go run cmd/syndicate/main.go
2021/01/25 16:37:25 error connecting to database: dial tcp: lookup db: no such host
Unable to connect to database when attempting to run:
$ go run cmd/syndicate/main.go
2021/01/25 16:37:25 error connecting to database: dial tcp: lookup db: no such host
&
$ migrate -source file://migrations -database postgres://postgres:secret#db:5432/syndicate?sslmode=disable up
error: dial tcp: lookup db on [2001:558:feed::1]:53: no such host
What do these two commands have in common?... Database URL. I am nearly certain my database URL is incorrect.
I have verified my postgres container is running:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4e578bf646c7 adminer "entrypoint.sh docke…" 3 days ago Up 3 days 0.0.0.0:8080->8080/tcp syndicate_adminer_1
729fc179aa6f postgres "docker-entrypoint.s…" 3 days ago Up 3 days 5432/tcp syndicate_db_1
Here's where I might be overlooking something...
$ docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------------
syndicate_adminer_1 entrypoint.sh docker-php-e ... Up 0.0.0.0:8080->8080/tcp
syndicate_db_1 docker-entrypoint.sh postgres Up 5432/tcp
5432/tcp???
I see that my adminer container is clearly mapped to my local port (0.0.0.0:8080->8080/tcp), however my postgres container is only showing 5432/tcp (and not 0.0.0.0:5432->5432/tcp)
I am new to docker.. Can anyone explain why my postgres port isn't associated with my local port?
Am I on the right track?
Here's my docker-compose.yml:
version: "3.8"
services:
db:
image: postgres
environment:
POSTGRES_DB: $POSTGRES_DB
POSTGRES_USER: $POSTGRES_USER
POSTGRES_PASSWORD: $POSTGRES_PASSWORD
migrate:
image: migrate/migrate
volumes:
- ./migrations:/migrations
depends_on:
- db
command: -source=file://migrations -database postgres://$POSTGRES_USER:$POSTGRES_PASSWORD#db:5432/$POSTGRES_DB?sslmode=disable up
adminer:
image: adminer
restart: always
ports:
- "8080:8080"
environment:
ADMINER_DEFAULT_SERVER: db
depends_on:
- db
PS. I tried adding port: "5432:5432" variable for db servicd
Browse my repository at this time in history
Thank you!
Connor
add to db service
ports:
- "5432:5432"
migrate -path D:/works/go/go-fiber-api-server/backend/platform/migrations -database "postgres://postgres:password#cgapp-postgres:5432/postgres?sslmode=disable" up
error: dial tcp: lookup cgapp-postgres: no such host
Then I have fixed this issue to change db-host name(cgapp-postgres) into "IP ADDRESS" or host.docker.internal.
migrate -path D:/works/go/go-fiber-api-server/backend/platform/migrations -database "postgres://postgres:password#100.100.100.100:5432/postgres?sslmode=disable" up
1/u create_init_tables (20.0987ms)
migrate -path D:/works/go/go-fiber-api-server/backend/platform/migrations -database "postgres://postgres:password#host.docker.internal:5432/postgres?sslmode=disable" up
1/u create_init_tables (20.0987ms)
"host.docker.internal" works.
I try to start 2 containers with the following docker compose file:
version: '2'
services:
client-app:
image: client-app:latest
build: ./client-app/Dockerfile
volumes:
- ./client-app:/usr/src/app
ports:
- 3000:8000
spring-boot-server:
build: ./spring-boot-server/Dockerfile
volumes:
- ./spring-boot-server:/usr/src/app
ports:
- 7000:7000
The spring boot server tries to connect to a remote database server which is on another host and network. Docker successfully starts the client-app containers but fails to start the spring-boot-server. This log is showing that the server crashed because it has failed to connect to the remote database:
2021-01-25 21:02:28.393 INFO 1 --- [main] com.zaxxer.hikari.HikariDataSource: HikariPool-1 - Starting...
2021-01-25 21:02:29.553 ERROR 1 --- [main] com.zaxxer.hikari.pool.HikariPool: HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
The Dockerfiles of both containers create valid images by which I can run manually the containers. It looks like there are some default network restrictions on containers started by a composing file.
Docker compose version running on Ubuntu:
docker-compose version 1.8.0, build unknown
=============================================
FURTHER INVESTIGATIONS:
I had created a Dockerfile
FROM ubuntu
RUN apt-get update
RUN apt-get install -y mysql-client
CMD mysql -A -P 3306 -h 8.8.8.8 --user=root --password=mypassword -e "SELECT VERSION()" mydatabase
along with a docker-compose.yml
version: '2'
services:
test-remote-db-compose:
build: .
ports:
- 8000:8000
to test aside the connectivity alone with the remote database. The test passed with success.
The problem has been misteriously solved, after doing this , a host mashine reboot and docker-compose up --build.
I'm trying to run SQL Server on my local Docker Desktop instance, and when run in Kubernetes mode, I get a strange error. Is there an error in my k8s.yaml file?
If I start it with docker-compose up and this yaml, it works fine:
version: '3'
services:
db:
image: "mcr.microsoft.com/mssql/server:2019-latest"
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=C#mpl3xEn0#gh!
ports:
- "1433:1433"
network_mode: bridge
Then I test the connection with sqlcmd -U sa -P C#mpl3xEn0#gh! -S localhost,1433 and it connects just fine.
If I start it with kubectl apply -f k8s.yaml following the instructions from https://learn.microsoft.com/en-us/sql/linux/tutorial-sql-server-containers-kubernetes I get an error connecting:
# based loosely on https://learn.microsoft.com/en-us/sql/linux/tutorial-sql-server-containers-kubernetes#create-the-deployment
apiVersion: v1
kind: Pod
metadata:
name: db
spec:
containers:
- name: db
image: mcr.microsoft.com/mssql/server:2019-latest
ports:
- containerPort: 1433
env:
- name: ACCEPT_EULA
value: 'Y'
- name: SA_PASSWORD
value: C#mpl3xEn0#gh!
resources: {}
---
apiVersion: v1
kind: Service
metadata:
name: db
spec:
type: NodePort
selector:
app: db
ports:
- protocol: TCP
port: 1433
targetPort: 1433
Then I try to connect from my local machine using sqlcmd -U sa -P C#mpl3xEn0#gh! -S localhost,31043 (swapping in the NodePort from kubectl get svc/db), and I get the error:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)
I get the same error from Azure Data Studio and SSMS.
If I kubectl exec ... into the container and run /opt/mssql-tools/bin/sqlcmd -U sa -P C#mpl3xEn0#gh! -S localhost,1433 it connects just fine.
Where's the error in my k8s.yaml file that causes SQL Server not accept connections when run in Kubernetes?
I've tried setting encrypt=false;trustServerCertificate=true; and results don't change.
Typo gets me again. Here's the missing piece of yaml:
...
metadata:
name: db
labels: # <--
app: db # <--
spec:
...
I forgot the labels: part. So the service carefully forwarded the traffic on to nothing, which didn't do a TLS handshake, and yielded me the erroneous error.
I met a problem when trying to apply CI/CD into our project using Github Action. The server has the firewall to enable access for a listed ip only.
I have found a method by using Github meta api https://api.github.com/meta but they denied to apply.
Is there any other way to apply this?
Our current ci.yml
name: remote ssh
on:
push:
branches: [ master ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: execute ssh command via using private key
uses: appleboy/ssh-action#master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.CICD_SSH_KEY }}
port: ${{ secrets.PORT }}
script:
pwd
In my case, I use an OpenVPN to access to the server.
About security. I think you should not load file VPN config to Git.
This is my config file.
name: remote ssh command to deploy
on:
push:
branches: [ master ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v1
- name: Install Open VPN
run: |
sudo apt-get install openvpn
echo "${{ secrets.VPN_FILE }}" > .github/vpn/config.ovpn
- name: Connect VPN
uses: golfzaptw/action-connect-ovpn#master
id: connect_vpn
with:
PING_URL: ${{ secrets.REMOTE_HOST }}
FILE_OVPN: '.github/vpn/config.ovpn'
env:
CA_CRT: ${{ secrets.CA_CRT}}
USER_CRT: ${{ secrets.USER_CRT }}
USER_KEY: ${{ secrets.USER_KEY }}
- name: Check Connect VPN
run: echo ${{ steps.connect_vpn.outputs.STATUS }}
- name: Execute ssh command via using private key
uses: appleboy/ssh-action#master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
key: ${{ secrets.CICD_SSH_KEY }}
port: ${{ secrets.PORT }}
script: |
pwd
cd ${{ secrets.REMOTE_TARGET }}
git pull
- name: kill vpn
if: always()
run: sudo killall openvpn
Follow https://github.com/marketplace/actions/connect-vpn#Example-prepare-file-.ovpn:
Copy data inside tag to encode base64 after that save to secret env github actions
Remove tag and replace to ca ca.crt cert user.crt key user.key
Aside OpenVPN, you can use Cloudflare WARP 1.1.1.1, its easy to use and no need for running any server or any kind of log in.
just make a job
name: remote ssh command to deploy
on:
push:
branches: [ master ]
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check Connect VPN
run: |
curl https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list
sudo apt update
sudo apt install cloudflare-warp
warp-cli --accept-tos register
warp-cli --accept-tos connect
put this there. Boom you're ready to go and surf anywhere.
Note:
the 1st line is to add the Cloudflare pkg host to apt host list because apt only use microsoft hosted pkg only, and it's not there. 2nd line for same reason.
5th line to register the service. --accept-tos part is for accepting TOS which needed to be done by human input if omitted
6th line Runs the service.
Full documentation here:
https://pkg.cloudflareclient.com/install
https://developers.cloudflare.com/warp-client/get-started/linux/
I've started to configure a CircleCI integration of my project. I've created the config file using the 2.0 standard. I've got it running smoothly, deploying and everything is working, except the phpunit tests that I've created. When I run the phpunit command, it returns an error (I believe he cannot connect to the database).
Unable to insert fixtures for "App\Test\TestCase\Model\Table\UsersTableTest" test case. SQLSTATE[HY000] [2002] No such file or directory in [***/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureManager.php, line 356]
Here's my test database config:
'test' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
// 'port' => '3306',
'database' => 'common_resources_test',
'username' => 'root',
'password' => 'root',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'quoteIdentifiers' => false,
],
Here's my circleCI code:
version: 2
jobs:
build:
working_directory: *removed*
parallelism: 1
shell: /bin/bash --login
environment:
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
DEBUG: true
docker:
- image: circleci/php:7.1-apache
steps:
- checkout
- run:
name: Install Maria DB
command: sudo apt-get install -y mariadb-server-10.1 mariadb-server-core-10.1 mariadb-client-10.1 mariadb-client-core-10.1
- run:
name: Initializing Mysql
working_directory: *removed*
command: 'sudo service mysql status || sudo service mysql restart; '
- run:
name: Set password
command: sudo mysql -u root -e "USE mysql; UPDATE user SET password=PASSWORD('root') WHERE User='root';FLUSH PRIVILEGES;"
- run:
name: Check settings
command: sudo mysql -u root -proot -e "USE mysql; SELECT host FROM user WHERE user = 'root';grant all privileges on *.* to root#'127.0.0.1' identified by 'root';FLUSH PRIVILEGES; SELECT host FROM user WHERE user = 'root';SELECT ##port;SELECT ##hostname;"
- run:
name: Restarting Mysql
working_directory: *removed*
command: 'sudo service mysql status || sudo service mysql restart; '
- run:
name: Create Mysql database and show current databases
command: sudo mysql -uroot -proot -e "create database common_resources_test;SHOW DATABASES"
- run:
name: Install required Libraries for PHP-GD
command: sudo apt-get update && sudo apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
- run:
name: Install PHP Extensions (PHP-GD && PDO-MYSQL)
command: sudo docker-php-ext-install gd && sudo docker-php-ext-install pdo_mysql
- run:
name: Install Other required Libraries for PHP & Activating PHP-GD and PDO-MYSQL
command: sudo docker-php-ext-install -j$(nproc) iconv && sudo docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && sudo docker-php-ext-install -j$(nproc) gd && sudo docker-php-ext-enable pdo_mysql
- run:
name: Create folder for Circle Artifacts and Circle Test Reports
working_directory: *removed*
command: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
- run:
name: Download Composer
command: curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
- run:
name: Running Composer Install
working_directory: *removed*
command: composer install --no-interaction;
- run:
name: Download Yarn
working_directory: *removed*
command: curl -o- -L https://yarnpkg.com/install.sh | bash
- run:
name: Install Yarn
working_directory: *removed*
command: sudo yarn install
- restore_cache:
keys:
- v1-dep-{{ .Branch }}-
- v1-dep-pre-production-
- v1-dep-
- save_cache:
key: v1-dep-{{ .Branch }}-{{ epoch }}
paths:
- vendor/bundle
- ~/virtualenvs
- ~/.m2
- ~/.ivy2
- ~/.bundle
- ~/.go_workspace
- ~/.gradle
- ~/.cache/bower
- ~/.composer/cache
- ~/.yarn-cache
- run:
name: Creating folder for PHPUnit Tests
working_directory: *removed*
command: mkdir -p $CIRCLE_TEST_REPORTS/phpunit
- run:
name: Running PHPUnit Tests
working_directory: *removed*
command: ./vendor/bin/phpunit --configuration ./phpunit.xml.dist --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit.xml
- store_test_results:
path: /tmp/circleci-test-results
- store_artifacts:
path: /tmp/circleci-artifacts
- store_artifacts:
path: /tmp/circleci-test-results
deployment:
docker:
- image: circleci/python:2.7-jessie
steps:
- run:
name: Install awsebcli
command: sudo pip install awsebcli
- run:
name: Deploy to S3
command: eb deploy --profile default
workflows:
version: 2
build_and_test:
jobs:
- build:
filters:
tags:
only: /.*/
- deployment:
requires:
- build
filters:
branches:
only: pre-production
Thanks for your time
I would handle the database the way it is in your config. You can use a second container for the database. Then set the DB creds with environment variables.
The config lines would look something like this:
- image: circleci/mariadb:10.1
environment:
MYSQL_DATABASE: "common_resources_test"
MYSQL_ROOT_PASSWORD: "root"
Founded a way to fix this problem. Basicly mysql root was not allowed to login using password. Had to set it up. Here's my app.php config:
'test_common_resources' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => '127.0.0.1',
'unix_socket' => '/var/run/mysqld/mysqld.sock',
'database' => 'common_resources_test',
'username' => 'root',
'password' => 'root',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
]
And here's my circleci config:
version: 2
jobs:
build:
working_directory: **removed**
parallelism: 1
shell: /bin/bash --login
environment:
CIRCLE_ARTIFACTS: /tmp/circleci-artifacts
CIRCLE_TEST_REPORTS: /tmp/circleci-test-results
DEBUG: true
docker:
- image: circleci/php:7.1-node-browsers
steps:
- run:
name: Install Maria DB
command: sudo apt-get install -y mariadb-server-10.1 mariadb-server-core-10.1 mariadb-client-10.1 mariadb-client-core-10.1
- run:
name: Initializing Mysql
command: 'sudo service mysql status || sudo service mysql restart; '
- run:
name: Set password
command: sudo mysql -u root -e "USE mysql; UPDATE user SET password=PASSWORD('root') WHERE User='root';FLUSH PRIVILEGES;"
- run:
name: Check settings
command: sudo mysql -u root -proot -e "USE mysql; UPDATE user SET plugin='mysql_native_password' WHERE User='root'; SELECT User, Host, plugin FROM mysql.user WHERE user = 'root';grant all privileges on *.* to root#'127.0.0.1' identified by 'root';FLUSH PRIVILEGES; SELECT host FROM user WHERE user = 'root';SELECT ##port;SELECT ##hostname;"
- run:
name: Restarting Mysql
command: 'sudo service mysql status || sudo service mysql restart; '
- run:
name: Create Mysql database and show current databases
command: sudo mysql -uroot -proot -e "create database common_resources_test;SHOW DATABASES"
- run:
name: Install required Libraries for PHP-GD
command: sudo apt-get update && sudo apt-get install -y libfreetype6-dev libjpeg62-turbo-dev libpng-dev
- run:
name: Install PHP Extensions (PHP-GD && PDO-MYSQL)
command: sudo docker-php-ext-install gd && sudo docker-php-ext-install pdo_mysql
- run:
name: Install Other required Libraries for PHP & Activating PHP-GD and PDO-MYSQL
command: sudo docker-php-ext-install -j$(nproc) iconv && sudo docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ && sudo docker-php-ext-install -j$(nproc) gd && sudo docker-php-ext-enable pdo_mysql
- run:
name: Create folder for Circle Artifacts and Circle Test Reports
command: mkdir -p $CIRCLE_ARTIFACTS $CIRCLE_TEST_REPORTS
- run:
name: Download Composer
command: curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
- run:
name: Download Yarn
command: curl -o- -L https://yarnpkg.com/install.sh | bash
- run:
name: Install Yarn
command: sudo yarn install
- restore_cache:
keys:
- v1-dep-{{ .Branch }}-
- v1-dep-pre-production-
- v1-dep-
- checkout
- run:
name: Running Composer Install
command: composer install --no-interaction;
- save_cache:
key: v1-dep-{{ .Branch }}-{{ epoch }}
paths:
- vendor/bundle
- ~/virtualenvs
- ~/.m2
- ~/.ivy2
- ~/.bundle
- ~/.go_workspace
- ~/.gradle
- ~/.cache/bower
- ~/.composer/cache
- ~/.yarn-cache
- run:
name: Creating folder for PHPUnit Tests
command: mkdir -p $CIRCLE_TEST_REPORTS/phpunit
- run:
name: Checking Mysql Status
command: 'sudo service mysql status'
- run:
name: Running PHPUnit Tests
command: ./vendor/bin/phpunit --configuration ./phpunit.xml.dist --log-junit $CIRCLE_TEST_REPORTS/phpunit/junit.xml
- store_test_results:
path: /tmp/circleci-test-results
- store_artifacts:
path: /tmp/circleci-artifacts
- store_artifacts:
path: /tmp/circleci-test-results
deployment:
docker:
- image: circleci/python:2.7-jessie
steps:
- run:
name: Install awsebcli
command: sudo pip install awsebcli
- run:
name: Deploy to S3
command: eb deploy --profile default
workflows:
version: 2
build_and_test:
jobs:
- build:
filters:
tags:
only: /.*/
- deployment:
requires:
- build
filters:
branches:
only: pre-production