{"id":1943,"date":"2023-10-04T12:56:55","date_gmt":"2023-10-04T03:56:55","guid":{"rendered":"https:\/\/www.kwonline.org\/memo2\/?p=1943"},"modified":"2023-10-04T12:56:55","modified_gmt":"2023-10-04T03:56:55","slug":"install-ansible-on-ubunt-20_04","status":"publish","type":"post","link":"https:\/\/www.kwonline.org\/memo2\/2023\/10\/04\/install-ansible-on-ubunt-20_04\/","title":{"rendered":"Ubuntu 20.04 \u306b Ansible \u3092\u5165\u308c\u308b"},"content":{"rendered":"<p>&nbsp;<br \/>\nAnsible \u4f7f\u3044\u59cb\u3081\u305f\u3089\u4fbf\u5229\u3060\u3063\u305f\u306e\u3067\u30e1\u30e2\u3002<br \/>\n\u307e\u305a\u306f Ansible \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt update -y\r\nsudo apt install software-properties-common\r\nsudo add-apt-repository --yes --update ppa:ansible\/ansible\r\nsudo apt install ansible\r\n<\/pre>\n<p>non-root \u30e6\u30fc\u30b6\u30fc\u3067\u306e\u4f5c\u696d\u3092\u8a31\u53ef\u3059\u308b\u305f\u3081\u306b ansible.cfg \u306b\u4e0b\u8a18\u3092\u8ffd\u52a0<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# \/etc\/ansible\/ansible.cfg\r\n&#x5B;default]\r\nallow_world_readable_tmpfiles = True\r\npipelining = True\r\n<\/pre>\n<p>\u3042\u3068\u306f Playbook \u3092\u7528\u610f\u3059\u308b\u3002<br \/>\n\u4f8b\u3048\u3070 Ansible \u3067 PostgreSQL \u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3092\u81ea\u52d5\u5316\u3059\u308b\u306a\u3089\u3053\u3046\u66f8\u304f\u3002<\/p>\n<pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\r\n---\r\n- name: Install PostgreSQL and configure\r\n  hosts: localhost\r\n  become: yes\r\n\r\n  tasks:\r\n    - name: Update APT cache\r\n      apt:\r\n        update_cache: yes\r\n\r\n    - name: Install PostgreSQL and related tools\r\n      apt:\r\n        name: \r\n          - postgresql\r\n          - postgresql-contrib\r\n        state: present\r\n\r\n    - name: Set PostgreSQL user password\r\n      become: yes\r\n      become_user: postgres\r\n      become_method: sudo\r\n      shell: |\r\n        psql -c &quot;ALTER USER postgres WITH PASSWORD '123456';&quot; # Change password here\r\n        exit\r\n\r\n    - name: Add PostgreSQL bin directory to PATH\r\n      lineinfile:\r\n        path: \/home\/orenomemo\/.profile # Replace username here\r\n        line: 'export PATH=$PATH:\/usr\/lib\/postgresql\/12\/bin'\r\n        owner: orenomemo # Change username here\r\n        state: present\r\n        create: yes\r\n    \r\n    - name: Enable PostgreSQL password login\r\n      postgresql_pg_hba:\r\n        dest: \/etc\/postgresql\/12\/main\/pg_hba.conf\r\n        contype: local\r\n        users: all\r\n        databases: all\r\n        method: md5\r\n        state: present\r\n\r\n    - name: Disable PostgreSQL peer login for postgres \r\n      postgresql_pg_hba:\r\n        dest: \/etc\/postgresql\/12\/main\/pg_hba.conf\r\n        contype: local\r\n        users: postgres\r\n        databases: all\r\n        method: peer\r\n        state: absent\r\n<\/pre>\n<p>Playbook \u3092\u7528\u610f\u3057\u305f\u3089\u5b9f\u884c\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nansible-playbook inst_psql.yml\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Ansible \u4f7f\u3044\u59cb\u3081\u305f\u3089\u4fbf\u5229\u3060\u3063\u305f\u306e\u3067\u30e1\u30e2\u3002 \u307e\u305a\u306f Ansible \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3002 sudo apt update -y sudo apt install software-properties-c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-1943","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1943","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/comments?post=1943"}],"version-history":[{"count":5,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1943\/revisions"}],"predecessor-version":[{"id":1949,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/1943\/revisions\/1949"}],"wp:attachment":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/media?parent=1943"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/categories?post=1943"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/tags?post=1943"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}