0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ansible学習メモ②(RHEL、CentOS関連)

Posted at

業務で最近Ansibleを使い始めました。私自身はエンジニア職ではないので普段コーディングをほとんどしないです。少しAnsibleがわかるように学習し始めています。

1.RHELマシンにパッケージをインストール

ansibleマニフェストを作成:
test.yaml

---
- name: ansible install a package in redhat system
  hosts: all
  become: true
  tasks:
    - name: install a package in redhat system
      ansible.builtin.dnf:
        name: wget
        state: present

inventoryファイルを以下のように設定

XX.XX.XX.XX ansible_ssh_private_key_file=~/XXXXX.pem

以下のコマンドを実行し、対象マシンにパッケージインストールを行う。

ansible-playbook -i inventory test.yaml

2.Apache httpd webサーバをインストール

四つのモジュールを使用する
ansible.builtin.yum
ansible.builtin.copy
ansible.builtin.service
ansible.posix.firewalld
※マニフェストを実行前、コレクションのインストールが必要

ansible-galaxy collection install ansible.posix

ansibleマニフェストを作成:
test.yaml

---
- name: deploy a web server apache httpd
  hosts: all
  become: true
  tasks:
    - name: httpd installed
      ansible.builtin.yum:
        name: httpd
        state: latest

    - name: custom index.html
      ansible.builtin.copy:
        dest: /var/www/html/index.html
        content: |
          Custom web Page

    - name: httpd service enabled
      ansible.builtin.service:
        name: httpd
        enabled: true
        state: started

    - name: open firewall
      ansible.posix.firewalld:
        service: http
        state: enabled
        immediate: true
        permanent: true

inventoryファイルを以下のように設定

XX.XX.XX.XX ansible_ssh_private_key_file=~/XXXXX.pem

(XX.XX.XX.XX: 対象マシンのIPアドレスまたはホスト名)

以下のコマンドを実行し、対象マシンにパッケージインストールを行う。

ansible-playbook -i inventory test.yaml

3.Google Chrome インストール

以下のモジュールを使用する
ansible.builtin.rpm_key (モジュール整合性確認ため、google chrome key 追加)
ansible.builtin.yum_repository (Google Chromeリポジトリ追加)
ansible.builtin.yum (Google Chrome インストール)

ansibleマニフェストを作成:
test.yaml

---
- name: install Google Chrome
  hosts: all
  become: true
  tasks:
    - name: Add Yum signing key
      ansible.builtin.rpm_key:
        key: https://dl.google.com/linux/linux_signing_key.pub
        state: present

    - name: Add repository into repo.d list
      ansible.builtin.yum_repository:
        name: google-chrome
        description: google-chrome repository
        baseurl: http://dl.google.com/linux/chrome/rpm/stable/x86_64
        enabled: true
        gpgcheck: true
        gpgkey: https://dl.google.com/linux/linux_signing_key.pub

    - name: Install google-chrome-stable
      ansible.builtin.yum:
        name: "google-chrome-stable"
        state: latest
        update_cache: true

inventoryファイルを以下のように設定

XX.XX.XX.XX ansible_ssh_private_key_file=~/XXXXX.pem

(XX.XX.XX.XX: 対象マシンのIPアドレスまたはホスト名)

以下のコマンドを実行し、対象マシンにパッケージインストールを行う。

ansible-playbook -i inventory test.yaml
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?