Git Product home page Git Product logo

ansible-role-poweruser's Introduction

CI

Ansible Role: poweruser

この role は、 Ansible が各サーバに接続するために利用するユーザ(ansible_user)を作成するための role です。

ansible_user で Ansible が接続できない場合に、(ディストリビューションごとに設定されたり、チームや個人で決めた)デフォルトのユーザを利用して Ansible が利用するユーザを作成します。

この role では次のことを行います。

  • ansible_user で接続可能か確認する。
  • ansible_user で接続できない場合、 poweruser_default_* の認証情報を利用して接続し、 ansible_user を作成・設定する。

この role では次のことを行いません。

  • poweruser_default_user の削除。

Requirements

この role には、 Ansible を実行するホスト上に sshpass がインストールされている必要があります。

Ubuntu

Ubuntu 20.04 の場合は apt でインストール可能です。

$ sudo apt update
$ sudo apt install sshpass

RHEL 系

RHEL7 の場合は EPEL からインストール可能です。

$ sudo yum install epel-release
$ sudo yum update
$ sudo yum sshpass

Role Variables

defaults/main.yml を参照してください。

Dependencies

None.

Example Playbook

[all]
my_host.example.com

[all:variables]
ansible_user: my_poweruser
ansible_ssh_pass: my_poweruser_password
- hosts: all
  gather_facts: false
  roles:
    - ktooi.poweruser
  vars:
    # for Raspberry pi OS
    poweruser_default_user: pi
    poweruser_default_ssh_pass: raspberry
    poweruser_default_become_pass: raspberry

ポイント

  • gather_factsfalse にする必要があります。対象ホストにログインができない場合には、 gather_facts を実行しても失敗するためです。
  • 例示している poweruser_default_* の認証情報は Raspberry Pi OS のデフォルトユーザの認証情報ですが、現行の Raspberry Pi OS では利用できないようになっているのでご注意ください。1

この Playbook は次のように動きます。

  1. my_poweruser というユーザと my_poweruser_password というパスワードで my_host.example.com に接続します。
  2. 1.の接続に失敗した場合、 poweruser_default_* の認証情報を利用して my_poweruser を作成します。上記例の場合は pi というユーザと raspberry というパスワードで my_host.example.com に接続し、 my_poweruser を作成します。
  3. 以降の Playbook では my_poweruser というユーザを利用して my_host.example.com に接続します。

Example usage

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

Footnotes

  1. An update to Raspberry Pi OS Bullseye - Raspberry Pi

ansible-role-poweruser's People

Contributors

ktooi avatar

Watchers

 avatar

ansible-role-poweruser's Issues

GitHub Actions の Molecule の試験で fail する

下記 Task でエラーが発生する。これは ubuntu2004 でのログ。

  TASK [ktooi.poweruser : create poweruser] **************************************
  fatal: [instance]: UNREACHABLE! => {"changed": false, "msg": "Failed to create temporary directory.In some cases, you may have been able to authenticate and did not have permissions on the target directory. Consider changing the remote tmp path in ansible.cfg to a path rooted in \"/tmp\", for more error information use -vvv. Failed command was: ( umask 77 && mkdir -p \"` echo unable to find user molecule_power: no matching entries in passwd file/.ansible/tmp `\"&& mkdir \"` echo unable to find user molecule_power: no matching entries in passwd file/.ansible/tmp/ansible-tmp-1651196768.069735-3014-280534103785229 `\" && echo ansible-tmp-1651196768.069735-3014-280534103785229=\"` echo unable to find user molecule_power: no matching entries in passwd file/.ansible/tmp/ansible-tmp-1651196768.069735-3014-280534103785229 `\" ), exited with result 126, stdout output: unable to find user molecule_power: no matching entries in passwd file\r\n", "unreachable": true}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.