[ root@2.2.2.2 ] adduser ansible # , Ansible [ root@2.2.2.2 ] su - ansible [ ansible@2.2.2.2 ] ssh-keygen -t rsa -b 4096 -C 'github' -f ~/.ssh/github_key # passphrase [ ansible@2.2.2.2 ] eval "$(ssh-agent -s)" [ ansible@2.2.2.2 ] ssh-add ~/.ssh/github_key [ ansible@2.2.2.2 ] cat ~/.ssh/github_key.pub # github_key.pub
[ root@1.1.1.1 ] yum install ansible [ root@1.1.1.1 ] adduser ansible # , Travis [ root@1.1.1.1 ] su - ansible [ ansible@1.1.1.1 ] ssh-keygen -t rsa -b 4096 -C 'ansible' -f ~/.ssh/ansible_key # passphrase [ ansible@1.1.1.1 ] eval "$(ssh-agent -s)" [ ansible@1.1.1.1 ] ssh-add ~/.ssh/ansible_key [ ansible@1.1.1.1 ] cat ~/.ssh/ansible_key.pub # ansible_key.pub
[ ansible@2.2.2.2 ] mcedit .ssh/authorized_keys [ ansible@2.2.2.2 ] chmod 600 .ssh/authorized_keys
[ ansible@1.1.1.1 ] mcedit /path/to/ansible/hosts.yml
[ansible] 2.2.2.2
[ ansible@1.1.1.1 ] mcedit /path/to/ansible/playbook.yml
- hosts: all user: ansible tasks: - name: Clone git repo git: repo: ssh://git@github.com/{github_username}/{github_repo}.git dest: /home/ansible/var/www/{github_repo} version: master accept_hostkey: yes force: yes
[ user@local ] gem install travis [ user@local ] travis login --auto
[ user@local ] ssh-keygen -t rsa -b 4096 -C 'travis' -f travis_key # passphrase Travis Ansible [ user@local ] cat travis_key.pub # travis_key.pub
[ ansible@1.1.1.1 ] mcedit /home/ansible/.ssh/authorized_keys [ ansible@1.1.1.1 ] chmod 600 /home/ansible/.ssh/authorized_keys
[ user@local ] travis encrypt-file travis_key --add
openssl aes-256-cbc -K $encrypted_412afa050e5f_key -iv $encrypted_412afa050e5f_iv -in travis_key.enc -out /tmp/travis_key -d
[ user@local ] git add travis_key.enc .travis.yml
[ user@local ] mcedit /path/to/repo/.travis.yml
language: node_js # node_js install: true # sudo: false branches: # master only: - master script: - openssl aes-256-cbc -K $encrypted_412afa050e5f_key -iv $encrypted_412afa050e5f_iv -in travis_key.enc -out /tmp/travis_key -d # - eval "$(ssh-agent -s)" - chmod 600 /tmp/travis_key - ssh-add /tmp/travis_key - ssh -o "StrictHostKeyChecking no" ansible@1.1.1.1 'ansible-playbook playbook.yml' # Ansible playbook
[ user@local ] git push origin master
The command "openssl aes-256-cbc -K $encrypted_412afa050e5f_key -iv $encrypted_412afa050e5f_iv -in travis_key.enc -out /tmp/travis_key -d" exited with 0. 0.01s$ eval "$(ssh-agent -s)" Agent pid 1842 The command "eval "$(ssh-agent -s)"" exited with 0. 0.01s$ chmod 600 /tmp/travis_key The command "chmod 600 /tmp/travis_key" exited with 0. 0.01s$ ssh-add /tmp/travis_key Identity added: /tmp/travis_key (/tmp/travis_key) The command "ssh-add /tmp/travis_key" exited with 0. 16.68s$ ssh -o "StrictHostKeyChecking no" ansible@2.2.2.2 'ansible-playbook playbook.yml' Warning: Permanently added '2.2.2.2' (ECDSA) to the list of known hosts. PLAY [all] ********************************************************************* TASK [setup] ******************************************************************* ok: [2.2.2.2] TASK [Clone git repo] ********************************************************** changed: [2.2.2.2] PLAY RECAP ********************************************************************* 2.2.2.2 : ok=1 changed=1 unreachable=0 failed=0 The command "ssh -o "StrictHostKeyChecking no" ansible@2.2.2.2 'ansible-playbook playbook.yml" exited with 0. Done. Your build exited with 0.
Source: https://habr.com/ru/post/325438/
All Articles