
Процесс создания Github токена, авторизации Ansible Galaxy в Github и добавления роли в Galaxy.
Установка Ansible
Устанавливаем Ansible:
sudo pacman -S ansible
resolving dependencies...
looking for conflicting packages...
Packages (17) python2-asn1crypto-0.23.0-1 python2-bcrypt-3.1.3-1 python2-cffi-1.10.0-1 python2-crypto-2.6.1-5 python2-cryptography-2.0.3-1 python2-enum34-1.1.6-1 python2-idna-2.6-1 python2-ipaddress-1.0.18-1 python2-jinja-2.9.6-1
python2-markupsafe-1.0-1 python2-paramiko-2.3.1-1 python2-ply-3.10-1 python2-pyasn1-0.3.6-1 python2-pycparser-2.18-1 python2-pynacl-1.1.2-1 python2-yaml-3.12-3 ansible-2.4.0.0-1
...
Проверяем:
ansible-galaxy login --help
Usage: ansible-galaxy login [options]
Options:
--github-token=TOKEN Identify with github token rather than username and
password.
...
Github token
Получение описано тут>>>.
Создаём токен для Ansible:

Как сказано в документации Galaxy — даём минимальный доступ, думаю status и public_repo будет достаточно:

Жмём внизу «Generate token«, и сохраняем токен где-то (я добавил в KeePass):

Создание аккаунта Ansible Galaxy
Переходим на страницу авторизации — https://galaxy.ansible.com/accounts/login/, выбираем Github, логинимся:
После авторизации — Ansible вышлет письмо для подтверждения, переходим по сылке — аккаунт готов:

Авторизуемся с рабочей машины, используя токен Github:
ansible-galaxy login --github-token=3e6d***f4ad
Successfully logged into Galaxy as setevoy2
Добавление роли
С помощью init
создаём структуру роли:
cd ~/Work/RTFM
ansible-galaxy init ansible-test-role
- ansible-test-role was created successfully
Обновляем meta/main.yml
, добавляем:
...
platforms:
- name: Any
...
galaxy_tags:
- test
...
Это минимальные данные, которые должны быть в описании роли.
Создаём Github репозиторий:
cd ansible-test-role/
git init
Initialized empty Git repository in /home/setevoy/Work/RTFM/ansible-test-role/.git/
git add .
git commit -m "Init"
[master (root-commit) e77b36e] Init
8 files changed, 110 insertions(+)
create mode 100644 README.md
create mode 100644 defaults/main.yml
create mode 100644 handlers/main.yml
create mode 100644 meta/main.yml
create mode 100644 tasks/main.yml
create mode 100644 tests/inventory
create mode 100644 tests/test.yml
create mode 100644 vars/main.yml
Добавляем remote
:
git remote add origin https://github.com/setevoy2/ansible-test-role.git
git remote -v
origin https://github.com/setevoy2/ansible-test-role.git (fetch)
origin https://github.com/setevoy2/ansible-test-role.git (push)
Создаём репозиторий в Github.
Можно из WebUI, можно через Github API:
curl -u 'setevoy2' https://api.github.com/user/repos -d "{\"name\":\"ansible-test-role\"}"
Enter host password for user 'setevoy2':
{
"id": 106155694,
"name": "ansible-test-role",
"full_name": "setevoy2/ansible-test-role",
"owner": {
"login": "setevoy2",
...
Пушим свою роль в этот репозиторий:
git push --set-upstream origin master
...
To https://github.com/setevoy2/ansible-test-role.git
* [new branch] master -> master
И выполняем import
роли в Absible Galaxy:
ansible-galaxy import setevoy2 ansible-test-role
Successfully submitted import request 143123
Starting import 143123: role_name=ansible-test-role repo=setevoy2/ansible-test-role
Accessing branch: master
Parsing and validating meta data.
Parsing galaxy_tags
Parsing platforms
Parsing and validating README
Adding repo tags as role versions
Removing old tags
Import completed
Status SUCCESS : warnings=0 errors=0
Проверяем:

Готово.