ログイン
IAM
ユーザグループ作成
ユーザ
作成
セキュリティ設定
- 互換性アプリのダウンロード
- QR表示
- MFAコード入力
-
インベントリはホストとグループの設定が可能 グループにホストを設定 グループにグループを設定が可能
-
custom_varsという変数に以下の*_var
を設定しどれが優先されるかを調査。
-
は変数定義をコメントアウトした状態。
# | テンプレート | Playbook | ホスト | グループ(Control) | グループ(ALL) | インベントリ | 結果 |
---|---|---|---|---|---|---|---|
1 | template_var | playbook_var | host_var | group_control_var | group_all_var | inventory_var | template_var |
2 | - | playbook_var | host_var | group_control_var | group_all_var | inventory_var | playbook_var |
3 | - | - | host_var | group_control_var | group_all_var | inventory_var | host_var |
4 | - | - | - | group_control_var | group_all_var | inventory_var | group_control_var |
5 | - | - | - | - | group_all_var | inventory_var | group_all_var |
6 | - | - | - | - | - | inventory_var | inventory_var |
- name: Vars test hosts: ALL va custom_vars: "playbook_var" tasks: - name: Vars debug: msg: "{{ custom_vars }}" tags: vars_test
-
#!/bin/sh # Variables GROUP="ansible_group" GROUPID=50000 USER="ansible_user" USERID=50001 PASSWORD="hoge" SSHPATH="/home/${USER}/.ssh" AUTHFILE="authorized_keys" SSHKEY="" create_group() { if getent group ${GROUP} > /dev/null 2>&1; then echo "${GROUP} already exists." else if sudo groupadd -g ${GROUPID} ${GROUP} > /dev/null 2>&1; then echo "${GROUP} created." else echo "Failed to create ${GROUP}: error code $?" && exit 8 fi fi } create_user() { if getent passwd ${USER} > /dev/null 2>&1; then echo "${USER} already exists." else if sudo useradd -u ${USERID} -g ${GROUP} -m -d /home/${USER} ${USER} > /dev/null 2>&1; then echo "${USER}:${PASSWORD}" | sudo chpasswd > /dev/null 2>&1 echo "${USER} created." else echo "Failed to create ${USER}: error code $?" && exit 8 fi fi } set_ssh_key() { if sudo mkdir -p ${SSHPATH} && sudo chown ${USER}:${GROUP} ${SSHPATH} && sudo chmod 700 ${SSHPATH}; then if echo ${SSHKEY} | sudo tee "${SSHPATH}/${AUTHFILE}" > /dev/null && sudo chmod 600 "${SSHPATH}/${AUTHFILE}" && sudo chown ${USER}:${GROUP} "${SSHPATH}/${AUTHFILE}"; then echo "SSH key file created and permissions set successfully" else echo "Failed to create SSH key file or set permissions" && exit 8 fi fi } setup_sudoers() { if grep ${GROUP} /etc/sudoers.d/${GROUP} > /dev/null 2>&1; then echo "${GROUP} already exists in sudoers." else if echo "%${GROUP} ALL=(ALL:ALL) NOPASSWD:ALL" | sudo tee /etc/sudoers.d/${GROUP} > /dev/null && sudo chmod 0440 /etc/sudoers.d/${GROUP}; then echo "Sudoers file setup for ${GROUP} completed." else echo "Failed to setup sudoers file for ${GROUP}." && exit 8 fi fi } create_group create_user set_ssh_key setup_sudoers exit 0
$ bash ./setup.sh ansible_group created. ansible_user created. SSH key file created and permissions set successfully Sudoers file setup for ansible_group completed. $
$ su - ansible_user Password: $
$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/ansible_user/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/ansible_user/.ssh/id_rsa. Your public key has been saved in /home/ansible_user/.ssh/id_rsa.pub. The key fingerprint is: - snip - +----[SHA256]-----+ $
$ cp ~/.ssh/id_rsa ~/.ssh/authorized_keys
$ su - admin $
$ sudo sh -c 'sed -i "s#SSHKEY=\"\"#SSHKEY=\"$(cat /home/ansible_user/.ssh/id_rsa.pub)\"#g" ./setup.sh'
$ scp setup.sh admin@control01:. $ scp setup.sh admin@control02:.
01,02で標準出力が違うのはadminユーザの設定テストをして状態が異なるため
$ ssh -t admin@control01 'sh ./setup.sh' [sudo] password for admin: ansible_group created. ansible_user created. SSH key file created and permissions set successfully Sudoers file setup for ansible_group completed. Connection to control01 closed. $ ssh -t admin@control02 'sh ./setup.sh' admin@control02's password: We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. [sudo] password for admin: ansible_group created. ansible_user created. SSH key file created and permissions set successfully Sudoers file setup for ansible_group completed. Connection to control02 closed.
$ su - ansible_user
[ansible_user@master01 ~]$ ssh ansible_user@control01 The authenticity of host 'control01 (192.168.50.41)' can't be established. ECDSA key fingerprint is SHA256:T------. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'control01,192.168.50.41' (ECDSA) to the list of known hosts. Activate the web console with: systemctl enable --now cockpit.socket [ansible_user@control01 ~]$ exit [ansible_user@master01 ~]$ ssh ansible_user@control02 The authenticity of host 'control02 (192.168.50.33)' can't be established. ECDSA key fingerprint is SHA256:jVWzlk+0fsrUkL5xxBLorwYb6NxFRSMXBOkpsvIrT6U. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'control02,192.168.50.33' (ECDSA) to the list of known hosts. Activate the web console with: systemctl enable --now cockpit.socket Register this system with Red Hat Insights: insights-client --register Create an account or view all your systems at https://red.ht/insights-dashboard [ansible_user@control02 ~]$ exit
$ sudo cat ~ansible_user/.ssh/id_rsa $
項目 | 変更前 | 変更後 |
---|---|---|
ユーザ名 | admin | ansible_user |
SSH秘密鍵 | - | 秘密鍵確認(後続手順で使用)の内容をペースト |
0行目の最後に実行ユーザが変わっていることを確認
-
ソースコントロールのタイプを手動にするため、事前にディレクトリを作成
以下を繰り返し追加 - control01 - control02 - master01
小グループとしてcontrolsとmastersを設定する
[root@master01 playbooks]# pwd /var/lib/awx/projects/playbooks [root@master01 playbooks]# cat main.yml - name: Hello World Sample hosts: controls tasks: - name: Hello Message debug: msg: "Hello World!" [root@master01 playbooks]#
先に作成した実行ホストリストを指定
先に作成したPlaybookの場所を指定
先に作成したプロジェクト配下に置いているPlaybookを指定
サブディレクトリも読み込まれる
ただしYaml内に hosts: xxx
の記載があるかのチェックを行なっている
無い場合はリストに表示されない
先に作成したサーバへのログイン方法を設定した認証情報を指定
認証エラーになる場合は、一度認証情報の設定から [ ] 起動プロンプトのチェックボックスにチェックを入れて実行する
クラスター内の複数のインスタンス(ノード)を一つのグループとして扱うことができます。 主にAAP環境を複数のインスタンス(サーバ)から構成するときに使用します。 また、最大同時実行ジョブ数等を設定できます。
インスタンスグループの名前を指定します。 名前は一意でなければならず、"controller"という名前に指定しないようにしてください。
新規インスタンスがオンラインになると、 このグループに自動的に最小限割り当てられるインスタンス数を入力します。
スライダーを使用して、新規インスタンスがオンラインになると、 このグループに自動的に最小限割り当てられるインスタンスの割合を選択します。
Ansible Automation Platformが一度に実行できるジョブの最大数を制御します。 これは、システムのリソース使用量を管理し、パフォーマンスを最適化するためのものです。
Ansibleが一度に実行できるタスクの最大数を制御します。 これは、Ansibleのタスクが並列に実行され、全体の実行時間が短縮される可能性があります。
Ansible Automation Platformにおける「組織」は、ユーザー、チーム、プロジェクト、およびインベントリーの論理コレクションで、 Automation Controllerオブジェクトの階層の最上位のオブジェクトです。
ユニークな名前を設定します。
説明を記載します。
この組織で管理可能な最大ホスト数。デフォルト値は 0 で、管理可能な数に制限がありません。
この組織を実行するインスタンスグループを選択します。
この組織内のジョブに使用される実行環境。 これは、実行環境がプロジェクト、ジョブテンプレート、またはワークフローレベルで 明示的に割り当てられていない場合にフォールバックとして使用されます。
Ansible GalaxyまたはAutomation Hub APIにアクセスするために必要な認証情報を指します。
Ansibleがタスクを実行する対象となるホスト(サーバー)のリストのことです。 これは、Ansibleがどのサーバーに対して作業を行うべきかを知るためのものです。
これはAnsibleが管理する対象となるホスト(サーバー)のリストです。 通常、テキストファイルに記述され、Ansibleがどのサーバーに対して作業を行うべきかを知るためのものです。
スマートインベントリーは、特定の条件に一致するホストを動的にグループ化する機能です。 これは、管理対象のホストが多いような大規模な環境で有効な手法で、一部のインベントリのみを表示する便利機能です。
この用語はAnsibleの公式ドキュメンテーションでは明確に定義されていません。しかし、一般的には、事前に作成(構築)され、特定のタスクやプロジェクトで使用するためのホストのリストを指すことが多いです。