{"id":34918,"date":"2024-08-26T15:14:51","date_gmt":"2024-08-26T08:14:51","guid":{"rendered":"http:\/\/jupitek.maudemo.vip\/index.php\/2024\/08\/26\/use-ansible-to-automate-configuration-of-web-server-log-server-and-database-server\/"},"modified":"2024-08-26T15:14:51","modified_gmt":"2024-08-26T08:14:51","slug":"use-ansible-to-automate-configuration-of-web-server-log-server-and-database-server","status":"publish","type":"post","link":"https:\/\/jupitek.maudemo.vip\/index.php\/2024\/08\/26\/use-ansible-to-automate-configuration-of-web-server-log-server-and-database-server\/","title":{"rendered":"S\u1eed d\u1ee5ng Ansible \u0111\u1ec3 t\u1ef1 \u0111\u1ed9ng c\u1ea5u h\u00ecnh Web Server, Log Server v\u00e0 Database Server"},"content":{"rendered":"<h2 id=\"what-is-ansible\">Ansible l\u00e0 g\u00ec?<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#what-is-ansible\"><\/a><\/h2>\n<p>Ansible l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 cung c\u1ea5p ph\u1ea7n m\u1ec1m m\u00e3 ngu\u1ed3n m\u1edf t\u1ef1 \u0111\u1ed9ng h\u00f3a vi\u1ec7c tri\u1ec3n khai \u1ee9ng d\u1ee5ng v\u00e0 c\u01a1 s\u1edf h\u1ea1 t\u1ea7ng CNTT. N\u00f3 nh\u1eb9 v\u00e0 kh\u00f4ng c\u00f3 t\u00e1c nh\u00e2n, ngh\u0129a l\u00e0 kh\u00f4ng c\u1ea7n c\u00e0i \u0111\u1eb7t ph\u1ea7n m\u1ec1m m\u00e1y kh\u00e1ch ho\u1eb7c m\u00e1y ch\u1ee7. Ansible s\u1eed d\u1ee5ng SSH v\u00e0 Python \u0111\u1ec3 th\u1ef1c hi\u1ec7n c\u00e1c t\u00e1c v\u1ee5 t\u1ef1 \u0111\u1ed9ng h\u00f3a c\u1ef1c k\u1ef3 h\u1eefu \u00edch c\u1ee7a n\u00f3.<\/p>\n<p>Trong h\u01b0\u1edbng d\u1eabn n\u00e0y b\u1ea1n:<\/p>\n<ul>\n<li>Tri\u1ec3n khai v\u00e0 c\u1ea5u h\u00ecnh n\u0103m Linode. M\u1ed9t l\u00e0 n\u00fat \u0111i\u1ec1u khi\u1ec3n Ansible v\u00e0 nh\u1eefng n\u00fat c\u00f2n l\u1ea1i l\u00e0 n\u00fat worker.<\/li>\n<li>C\u1ea5u h\u00ecnh v\u00e0 ch\u1ea1y playbook Ansible \u0111\u1ec3 c\u1ea5u h\u00ecnh c\u00e1c n\u00fat l\u00e0m vi\u1ec7c.<\/li>\n<li>Ki\u1ec3m tra m\u00e1y ch\u1ee7 web v\u00e0 m\u00e1y ch\u1ee7 nh\u1eadt k\u00fd \u0111ang ch\u1ea1y c\u1ee7a b\u1ea1n.<\/li>\n<li>Quan tr\u1ecdngC\u00e1c h\u01b0\u1edbng d\u1eabn m\u1eabu trong h\u01b0\u1edbng d\u1eabn n\u00e0y t\u1ea1o ra n\u0103m&nbsp;<a href=\"https:\/\/www.linode.com\/pricing\" target=\"_blank\" rel=\"noreferrer noopener\">Linode 1GB<\/a>&nbsp;. Ch\u00fang th\u00eam c\u00e1c t\u00e0i nguy\u00ean c\u00f3 th\u1ec3 thanh to\u00e1n v\u00e0o t\u00e0i kho\u1ea3n Linode c\u1ee7a b\u1ea1n. N\u1ebfu b\u1ea1n kh\u00f4ng mu\u1ed1n ti\u1ebfp t\u1ee5c s\u1eed d\u1ee5ng c\u00e1c Linode \u0111\u00e3 t\u1ea1o, h\u00e3y x\u00f3a ch\u00fang sau khi ho\u00e0n t\u1ea5t h\u01b0\u1edbng d\u1eabn n\u00e0y.N\u1ebfu sau \u0111\u00f3 b\u1ea1n x\u00f3a c\u00e1c t\u00e0i nguy\u00ean n\u00e0y, b\u1ea1n s\u1ebd ch\u1ec9&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/products\/platform\/billing\/\">b\u1ecb t\u00ednh ph\u00ed cho th\u1eddi gian<\/a>&nbsp;c\u00e1c t\u00e0i nguy\u00ean \u0111\u00f3 c\u00f3 trong t\u00e0i kho\u1ea3n c\u1ee7a b\u1ea1n.<\/li>\n<\/ul>\n<h2 id=\"prerequisites\">\u0110i\u1ec1u ki\u1ec7n ti\u00ean quy\u1ebft<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#prerequisites\"><\/a><\/h2>\n<ul>\n<li>Hi\u1ec3u bi\u1ebft \u1edf m\u1ee9c trung b\u00ecnh v\u1ec1 Bash shell v\u00e0 c\u00e1c ti\u1ec7n \u00edch c\u1ee7a n\u00f3.<\/li>\n<li>C\u00e0i \u0111\u1eb7t&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/products\/tools\/cli\/guides\/install\/\">Linode CLI<\/a>&nbsp;ho\u1eb7c b\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng&nbsp;<a href=\"https:\/\/cloud.linode.com\/linodes\" target=\"_blank\" rel=\"noreferrer noopener\">Linode Cloud Manager<\/a>&nbsp;.\n<ul>\n<li>S\u1eed d\u1ee5ng CLI cho ph\u00e9p b\u1ea1n ti\u1ebft ki\u1ec7m th\u1eddi gian t\u1ea1o, d\u00e1n nh\u00e3n v\u00e0 g\u1eafn th\u1ebb Linode.<\/li>\n<\/ul>\n<\/li>\n<li>T\u1ea1o m\u1ed9t th\u01b0 m\u1ee5c m\u1edbi \u0111\u1ec3 l\u00e0m vi\u1ec7c. V\u00ed d\u1ee5, b\u1ea1n c\u00f3 th\u1ec3 \u0111\u1eb7t t\u00ean l\u00e0&nbsp;<strong>\u201cAnsible_Infra\u201d<\/strong>&nbsp;.<\/li>\n<\/ul>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: C\u00e1c b\u01b0\u1edbc trong h\u01b0\u1edbng d\u1eabn n\u00e0y \u0111\u01b0\u1ee3c vi\u1ebft cho ng\u01b0\u1eddi d\u00f9ng kh\u00f4ng ph\u1ea3i root. C\u00e1c l\u1ec7nh y\u00eau c\u1ea7u quy\u1ec1n n\u00e2ng cao \u0111\u01b0\u1ee3c th\u00eam ti\u1ec1n t\u1ed1&nbsp;<code>sudo<\/code>. N\u1ebfu b\u1ea1n kh\u00f4ng quen v\u1edbi&nbsp;<code>sudo<\/code> l\u1ec7nh n\u00e0y, h\u00e3y xem h\u01b0\u1edbng d\u1eabn&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/guides\/linux-users-and-groups\/\">Ng\u01b0\u1eddi d\u00f9ng v\u00e0 Nh\u00f3m<\/a>&nbsp;.<\/p>\n<h3 id=\"create-one-ansible-control-node-and-four-managed-nodes\">T\u1ea1o m\u1ed9t n\u00fat \u0111i\u1ec1u khi\u1ec3n Ansible v\u00e0 b\u1ed1n n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#create-one-ansible-control-node-and-four-managed-nodes\"><\/a><\/h3>\n<p>Ghi ch\u00faPh\u1ea7n n\u00e0y y\u00eau c\u1ea7u b\u1ea1n ph\u1ea3i c\u00e0i \u0111\u1eb7t v\u00e0 c\u1ea5u h\u00ecnh&nbsp;<\/p>\n<p><a href=\"https:\/\/www.linode.com\/docs\/products\/tools\/cli\/guides\/install\/\">Linode CLI<\/a>&nbsp;tr\u00ean m\u00e1y t\u00ednh c\u1ee7a m\u00ecnh.<\/p>\n<p>Tr\u00ean m\u00e1y c\u1ee5c b\u1ed9 c\u1ee7a b\u1ea1n, h\u00e3y thi\u1ebft l\u1eadp m\u1ed9t bi\u1ebfn m\u00f4i tr\u01b0\u1eddng \u0111\u1ec3 l\u01b0u tr\u1eef t\u1ea1m th\u1eddi m\u1eadt kh\u1ea9u. Bi\u1ebfn m\u00f4i tr\u01b0\u1eddng n\u00e0y s\u1ebd \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng trong c\u00e1c b\u01b0\u1edbc sau trong m\u1ed9t&nbsp;<code>for<\/code>v\u00f2ng l\u1eb7p \u0111\u1ec3 t\u1ea1o n\u0103m Linode. Thay th\u1ebf&nbsp;<code>yourrootpassword<\/code>cho m\u1eadt kh\u1ea9u an to\u00e0n v\u00ec m\u1eadt kh\u1ea9u n\u00e0y \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng l\u00e0m m\u1eadt kh\u1ea9u g\u1ed1c cho t\u1ea5t c\u1ea3 c\u00e1c Linode m\u1edbi t\u1ea1o c\u1ee7a b\u1ea1n.<\/p>\n<pre class=\"wp-block-code\"><code>pass=yourrootpassword\n<\/code><\/pre>\n<p>Ki\u1ec3m tra xem m\u1eadt kh\u1ea9u n\u00e0y c\u00f3 ho\u1ea1t \u0111\u1ed9ng kh\u00f4ng b\u1eb1ng c\u00e1ch ch\u1ea1y&nbsp;<code>echo $pass<\/code>. B\u1ea1n s\u1ebd th\u1ea5y m\u1eadt kh\u1ea9u m\u1edbi t\u1ea1o c\u1ee7a m\u00ecnh l\u00e0 \u0111\u1ea7u ra.<\/p>\n<pre class=\"wp-block-code\"><code>echo $pass\nyourrootpassword<\/code><\/pre>\n<p>Ch\u1ea1y l\u1ec7nh b\u00ean d\u01b0\u1edbi \u0111\u1ec3 t\u1ea1o n\u0103m Linode.<\/p>\n<pre class=\"wp-block-code\"><code>for i in {1..5}; do linode-cli linodes create --root_pass $pass; done\n<\/code><\/pre>\n<p>\u0110\u1ea7u ra c\u1ee7a b\u1ea1n s\u1ebd gi\u1ed1ng nh\u01b0 v\u00ed d\u1ee5 sau:<\/p>\n<pre class=\"wp-block-code\"><code>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 id       \u2502 label          \u2502 region  \u2502 type        \u2502 image              \u2502 status       \u2502 ipv4           \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 31202535 \u2502 linode31202535 \u2502 us-east \u2502 g6-nanode-1 \u2502 linode\/ubuntu20.04 \u2502 provisioning \u2502 192.0.2.0      \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 id       \u2502 label          \u2502 region  \u2502 type        \u2502 image              \u2502 status       \u2502 ipv4           \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 31202548 \u2502 linode31202548 \u2502 us-east \u2502 g6-nanode-1 \u2502 linode\/ubuntu20.04 \u2502 provisioning \u2502 192.0.2.1      \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 id       \u2502 label          \u2502 region  \u2502 type        \u2502 image              \u2502 status       \u2502 ipv4            \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 31202559 \u2502 linode31202559 \u2502 us-east \u2502 g6-nanode-1 \u2502 linode\/ubuntu20.04 \u2502 provisioning \u2502 192.0.2.2       \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 id       \u2502 label          \u2502 region  \u2502 type        \u2502 image              \u2502 status       \u2502 ipv4            \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 31202570 \u2502 linode31202570 \u2502 us-east \u2502 g6-nanode-1 \u2502 linode\/ubuntu20.04 \u2502 provisioning \u2502 192.0.2.3       \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n\u2502 id       \u2502 label          \u2502 region  \u2502 type        \u2502 image              \u2502 status       \u2502 ipv4            \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 31202576 \u2502 linode31202576 \u2502 us-east \u2502 g6-nanode-1 \u2502 linode\/ubuntu20.04 \u2502 provisioning \u2502 192.0.2.4       \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/code><\/pre>\n<h3 id=\"store-your-linode-ids-in-a-temporary-file\">L\u01b0u tr\u1eef ID Linode c\u1ee7a b\u1ea1n trong m\u1ed9t t\u1ec7p t\u1ea1m th\u1eddi<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#store-your-linode-ids-in-a-temporary-file\"><\/a><\/h3>\n<p>S\u1eed d\u1ee5ng l\u1ec7nh sau \u0111\u1ec3 in n\u0103m ID Linode cu\u1ed1i c\u00f9ng v\u00e0 chuy\u1ec3n h\u01b0\u1edbng \u0111\u1ea7u ra \u0111\u1ebfn t\u1ec7p&nbsp;<code>tmp.txt<\/code>. B\u1ea1n c\u00f3 th\u1ec3 s\u1eed d\u1ee5ng c\u00e1c ID Linode n\u00e0y \u0111\u1ec3 g\u1eafn th\u1ebb v\u00e0 d\u00e1n nh\u00e3n cho Linode c\u1ee7a m\u00ecnh.<\/p>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: Vi\u1ec7c g\u1eafn th\u1ebb v\u00e0 d\u00e1n nh\u00e3n Linode gi\u00fap Linode Cloud Manager c\u1ee7a b\u1ea1n \u0111\u01b0\u1ee3c s\u1eafp x\u1ebfp khoa h\u1ecdc.<\/p>\n<pre class=\"wp-block-code\"><code>linode-cli linodes list --text | tail -5 | awk '{print $1}' &gt; tmp.txt\n<\/code><\/pre>\n<h3 id=\"tag-your-ansible-linodes\">\u0110\u00e1nh d\u1ea5u Ansible Linodes c\u1ee7a b\u1ea1n<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#tag-your-ansible-linodes\"><\/a><\/h3>\n<p>S\u1eed d\u1ee5ng d\u00f2ng m\u00e3 sau \u0111\u1ec3 g\u1eafn th\u1ebb Linodes v\u1edbi \u201cAnsible\u201d. Th\u1ef1c hi\u1ec7n thao t\u00e1c n\u00e0y \u0111\u1ec3 nh\u00f3m c\u00e1c Linodes l\u1ea1i v\u1edbi nhau trong Cloud Manager.<\/p>\n<pre class=\"wp-block-code\"><code>for i in $(cat tmp.txt); do linode-cli linodes update --tags Ansible $i; done\n<\/code><\/pre>\n<h3 id=\"label-your-ansible-linodes\">Nh\u00e3n Linode Ansible c\u1ee7a b\u1ea1n<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#label-your-ansible-linodes\"><\/a><\/h3>\n<p>L\u1eb7p qua c\u00e1c ID Linode t\u1eeb&nbsp;<code>tmp.txt<\/code>t\u1ec7p b\u1ea1n \u0111\u00e3 t\u1ea1o tr\u01b0\u1edbc \u0111\u00f3. Sau \u0111\u00f3, g\u00e1n cho m\u1ed7i Linode m\u1ed9t nh\u00e3n \u0111\u01b0\u1ee3c \u0111\u00e1nh s\u1ed1 (&nbsp;<code>vm1<\/code>\u0111\u1ebfn&nbsp;<code>vm5<\/code>) b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng d\u00f2ng m\u00e3 sau.<\/p>\n<pre class=\"wp-block-code\"><code>i=1; for j in $(cat tmp.txt); do linode-cli linodes update --label vm$i $j; let \"i++\"; done\n<\/code><\/pre>\n<p>N\u1ebfu b\u1ea1n ki\u1ec3m tra Giao di\u1ec7n ng\u01b0\u1eddi d\u00f9ng c\u1ee7a Cloud Manager, b\u1ea1n c\u00f3 th\u1ec3 th\u1ea5y n\u0103m Linode n\u00e0y \u0111\u01b0\u1ee3c nh\u00f3m l\u1ea1i d\u01b0\u1edbi th\u1ebb \u201cAnsible\u201d v\u00e0 \u0111\u01b0\u1ee3c g\u1eafn nh\u00e3n&nbsp;<code>vm1<\/code>th\u00f4ng qua&nbsp;<code>vm5<\/code>.<\/p>\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/cloud-gui-01_hu2e4458b109c1761b863b5a9d93df25f1_129258_1572x0_resize_q71_bgfafafc_catmullrom_3.jpg\" alt=\"Giao di\u1ec7n ng\u01b0\u1eddi d\u00f9ng c\u1ee7a Cloud Manager\" title=\"Giao di\u1ec7n ng\u01b0\u1eddi d\u00f9ng Cloud Manager hi\u1ec3n th\u1ecb 5 Linode \u0111\u01b0\u1ee3c nh\u00f3m v\u00e0 d\u00e1n nh\u00e3n.\"\/><\/figure>\n<h2 id=\"create-setup-files-to-configure-the-ansible-control-node-and-worker-nodes\">T\u1ea1o c\u00e1c t\u1ec7p thi\u1ebft l\u1eadp \u0111\u1ec3 c\u1ea5u h\u00ecnh n\u00fat \u0111i\u1ec1u khi\u1ec3n Ansible v\u00e0 n\u00fat Worker<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#create-setup-files-to-configure-the-ansible-control-node-and-worker-nodes\"><\/a><\/h2>\n<p>T\u1ea1o ba t\u1ec7p c\u00f3 t\u00ean l\u00e0&nbsp;<code>ansibleCN_setup.sh<\/code>,&nbsp;<code>ansibleMN_setup.sh<\/code>, v\u00e0&nbsp;<code>myplaybook.yml<\/code>. S\u1eed d\u1ee5ng tr\u00ecnh so\u1ea1n th\u1ea3o v\u0103n b\u1ea3n, sao ch\u00e9p v\u00e0 d\u00e1n m\u00e3 trong c\u00e1c t\u1ec7p v\u00ed d\u1ee5 b\u00ean d\u01b0\u1edbi v\u00e0o t\u1eebng t\u1ec7p t\u01b0\u01a1ng \u1ee9ng. C\u00e1c t\u1ec7p thi\u1ebft l\u1eadp gi\u00fap b\u1ea3o m\u1eadt Linode c\u1ee7a b\u1ea1n, c\u00e0i \u0111\u1eb7t ph\u1ea7n m\u1ec1m c\u1ea7n thi\u1ebft v\u00e0 t\u1ea1o ng\u01b0\u1eddi d\u00f9ng gi\u1edbi h\u1ea1n tr\u00ean phi\u00ean b\u1ea3n c\u1ee7a b\u1ea1n. T\u1ec7p playbook&nbsp;<code>myplaybook.yml<\/code>l\u00e0 t\u1ec7p m\u00e0 Ansible s\u1eed d\u1ee5ng \u0111\u1ec3 c\u1ea5u h\u00ecnh c\u00e1c n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd.<\/p>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: M\u1ed9t c\u00e1ch nhanh h\u01a1n l\u00e0 b\u1ea1n c\u00f3 th\u1ec3 l\u1ea5y&nbsp;<code>wget<\/code>c\u00e1c t\u1ec7p c\u1ea5u h\u00ecnh t\u1eeb&nbsp;<a href=\"https:\/\/github.com\/bennettnw2\/Ansible_webserver_infra_files\" target=\"_blank\" rel=\"noreferrer noopener\">kho l\u01b0u tr\u1eef GitHub c\u1ee7a t\u00e1c gi\u1ea3<\/a>&nbsp;v\u00e0 l\u01b0u ch\u00fang v\u00e0o th\u01b0 m\u1ee5c l\u00e0m vi\u1ec7c c\u1ee5c b\u1ed9&nbsp;<code>Ansible_Infra<\/code>m\u00e0 b\u1ea1n \u0111\u00e3 t\u1ea1o tr\u01b0\u1edbc \u0111\u00f3.<\/p>\n<pre class=\"wp-block-code has-background\" style=\"background-color:#74f78c33\"><code>wget https:\/\/raw.githubusercontent.com\/bennettnw2\/Ansible_webserver_infra_files\/main\/ansibleCN_setup.sh\nwget https:\/\/raw.githubusercontent.com\/bennettnw2\/Ansible_webserver_infra_files\/main\/ansibleMN_setup.sh\nwget https:\/\/raw.githubusercontent.com\/bennettnw2\/Ansible_webserver_infra_files\/mai<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>#! \/bin\/bash\n# This is the script to run to setup an Ansible control node.\n\necho \"##########################################################\"\necho \"# Update and Secure Linode Instance                      #\"\necho \"##########################################################\"\n\napt update\napt upgrade -y\n\nhostnamectl set-hostname CtlNode\n\n# Secure ssh a bit with no root login and no x11 forwarding\n# Need to remove host key checking for Ansible to run properly\nsed -in 's\/PermitRootLogin yes\/PermitRootLogin no\/' \/etc\/ssh\/sshd_config\nsed -in 's\/X11Forwarding yes\/X11Forwarding no\/' \/etc\/ssh\/sshd_config\nsed -in 's\/#   StrictHostKeyChecking ask\/StrictHostKeyChecking no\/' \/etc\/ssh\/ssh_config\n\necho \"##########################################################\"\necho \"# Installing Software                                    #\"\necho \"##########################################################\"\n# Install Software\n# ====================================================================================================\napt install sshpass -y\napt install ansible -y\napt install fail2ban -y\napt install python3-pip -y\npip3 install passlib\n\n# Configure Software\n# ====================================================================================================\n# fail2ban\n# ========\nsystemctl enable fail2ban.service\nsystemctl start fail2ban.service\n# ufw\n# ========\nufw allow openssh\nyes | ufw enable\nufw status\n\necho \"##########################################################\"\necho \"# Creating limited user                                  #\"\necho \"##########################################################\"\necho \"\"\necho \"Please enter preferred username: \"\nread USERNAME\n# Create limited user and give sudo privileges.\nuseradd -m -G sudo -s \/bin\/bash $USERNAME\npasswd $USERNAME\n\nmv ansibleMN_setup.sh myplaybook.yml \/home\/$USERNAME\n\n# Create passwordless sudo for user $USERNAME\n#+ and add file in \/etc\/sudoers.d\/\necho \"$USERNAME ALL=(ALL) NOPASSWD:ALL\" &gt; \/etc\/sudoers.d\/10-user-$USERNAME\nchmod 440 \/etc\/sudoers.d\/10-user-$USERNAME\nvisudo -c\n\n# Create an ssh key for the user.\nmkdir \/home\/$USERNAME\/.ssh\nssh-keygen -t rsa -b 2048 -f \/home\/$USERNAME\/.ssh\/id_rsa -q -N ''\n\n# Set file permissions for the user.\nchown -R $USERNAME:$USERNAME \/home\/$USERNAME\/.ssh\nchown $USERNAME:$USERNAME \/home\/$USERNAME\/myplaybook.yml\n\necho \"##########################################################\"\necho \"# Dunzo. Poke around if you like.  I recommend a reboot. #\"\necho \"##########################################################\"<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\n# This is the script to run in order to setup Ansible managed nodes.\n\necho \"##########################################################\"\necho \"# Update and Secure Linode Instance                      #\"\necho \"##########################################################\"\napt update\napt upgrade -y\n\n# Secure ssh a bit with no root login and no x11 forwarding.\nsed -in 's\/PermitRootLogin yes\/PermitRootLogin no\/' \/etc\/ssh\/sshd_config\nsed -in 's\/X11Forwarding yes\/X11Forwarding no\/' \/etc\/ssh\/sshd_config\nsed -in 's\/#PubkeyAuthentication\/PubkeyAuthentication\/' \/etc\/ssh\/sshd_config\n\napt install fail2ban -y\nsystemctl enable fail2ban.service\nsystemctl start fail2ban.service\n\necho \"##########################################################\"\necho \"# Creating limited user                                  #\"\necho \"##########################################################\"\necho \"\"\necho \"Please enter preferred username: \"\nread USERNAME\n# Create limited user and give sudo privileges.\nuseradd -m -G sudo -s \/bin\/bash $USERNAME\npasswd $USERNAME\n\n# Create passwordless sudo execution for user $USERNAME\n#+ and add file in \/etc\/sudoers.d\/\necho \"$USERNAME ALL=(ALL) NOPASSWD:ALL\" &gt; \/etc\/sudoers.d\/10-user-$USERNAME\nchmod 440 \/etc\/sudoers.d\/10-user-$USERNAME\nvisudo -c\n\necho \"##########################################################\"\necho \"# Dunzo. Poke around if you like.  I recommend a reboot. #\"\necho \"##########################################################\"<\/code><\/pre>\n<p>Ansible playbook l\u00e0 th\u1ee9 l\u00e0m cho Ansible tr\u1edf th\u00e0nh ph\u1ea7n m\u1ec1m m\u1ea1nh m\u1ebd. C\u00fa ph\u00e1p c\u1ee7a c\u00e1c t\u00e1c v\u1ee5 r\u1ea5t gi\u1ed1ng v\u1edbi ng\u00f4n ng\u1eef th\u00f4ng th\u01b0\u1eddng v\u00e0 do \u0111\u00f3, l\u00e0m cho t\u1ec7p playbook c\u00f3 th\u1ec3 \u0111\u1ecdc \u0111\u01b0\u1ee3c b\u1eb1ng con ng\u01b0\u1eddi. Theo th\u00f4ng l\u1ec7 t\u1ed1t nh\u1ea5t, h\u00e3y \u0111\u1ea3m b\u1ea3o t\u00ean t\u00e1c v\u1ee5 c\u1ee7a b\u1ea1n c\u00f3 t\u00ednh m\u00f4 t\u1ea3 v\u00e0 ch\u00ednh x\u00e1c. Xem l\u1ea1i t\u00ean c\u1ee7a c\u00e1c t\u00e1c v\u1ee5 trong&nbsp;<code>myplaybook.yml<\/code>, \u0111\u1ec3 t\u00ecm hi\u1ec3u xem m\u1ed7i t\u00e1c v\u1ee5 \u0111\u01b0\u1ee3c cho l\u00e0 th\u1ef1c hi\u1ec7n nh\u1eefng g\u00ec.<\/p>\n<pre class=\"wp-block-code\"><code>---\n- hosts: webservers\n  become: yes\n  tasks:\n    - name: \"Install Apache Server\"\n      apt:\n        name: apache2\n        state: present\n\n    - name: \"Enable and Start Apache Server\"\n      service:\n        name: apache2\n        enabled: yes\n        state: started\n\n    - name: \"Install Firewalld\"\n      apt:\n        name: firewalld\n        state: present\n\n    - name: \"Enable and start firewalld server\"\n      service:\n        name: firewalld\n        enabled: yes\n        state: started\n\n    - name: \"Open Firewall Port\"\n      firewalld:\n        service: http\n        immediate: true\n        permanent: true\n        state: enabled\n\n    - name: \"Create web admin group\"\n      group:\n        name: web\n        state: present\n\n    - name: \"Create web admin user\"\n      user:\n        name: webadm\n        comment: \"Web Admin\"\n        password: {{ HASHED_PASSWORD }}\n        groups: web\n        append: yes\n\n    - name: \"Set content directory group\/permissions\"\n      file:\n        path: \/var\/www\/html\n        owner: root\n        group: web\n        state: directory\n        mode: u=rwx,g=rwx,o=rx,g+s\n\n    - name: \"Create default page content\"\n      copy:\n        content: \"Welcome to {{ ansible_fqdn }} on {{ ansible_default_ipv4.address }}\"\n        dest: \/var\/www\/html\/index.html\n        owner: webadm\n        group: web\n        mode: u=rw,g=rw,o=r\n\n- hosts: dbservers\n  become: yes\n  tasks:\n    - name: \"Install MariaDB Server\"\n      apt:\n        name: mariadb-server\n        state: present\n\n    - name: \"Enable and start MariaDB server\"\n      service:\n        name: mariadb\n        enabled: yes\n        state: started\n\n- hosts: logservers\n  become: yes\n  tasks:\n    - name: \"Configure rsyslog remote log reception over udp\"\n      lineinfile:\n        path: \/etc\/rsyslog.conf\n        line: \"{{ item }}\"\n        state: present\n      with_items:\n        - '$ModLoad imudp'\n        - '$UDPServerRun 514'\n      notify:\n        - restart rsyslogd\n\n    - name: \"Install Firewalld\"\n      apt:\n        name: firewalld\n        state: present\n\n    - name: \"Enable and start firewalld server\"\n      service:\n        name: firewalld\n        enabled: yes\n        state: started\n\n    - name: \"Open firewall port\"\n      firewalld:\n        port: 514\/udp\n        immediate: true\n        permanent: true\n        state: enabled\n\n  handlers:\n    - name: \"restart rsyslogd\"\n      service:\n        name: rsyslog\n        state: restarted\n\n- hosts: lamp\n  become: yes\n  tasks:\n    - name: configure rsyslog\n      lineinfile:\n        path: \/etc\/rsyslog.conf\n        line: '*.* @{{ LOG_IP_ADDRESS }}'\n        state: present\n      notify:\n        - restart rsyslogd\n\n  handlers:\n    - name: \"restart rsyslogd\"\n      service:\n        name: rsyslog\n        state: restarted<\/code><\/pre>\n<h2 id=\"configure-your-control-node\">C\u1ea5u h\u00ecnh n\u00fat \u0111i\u1ec1u khi\u1ec3n c\u1ee7a b\u1ea1n<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#configure-your-control-node\"><\/a><\/h2>\n<p>S\u1eed d\u1ee5ng&nbsp;<code>scp<\/code>, c\u00e1c t\u1ec7p tr\u00ean \u0111\u01b0\u1ee3c g\u1eedi \u0111\u1ebfn n\u00fat \u0111i\u1ec1u khi\u1ec3n Ansible. Sau \u0111\u00f3, b\u1ea1n c\u00f3 th\u1ec3 \u0111\u0103ng nh\u1eadp v\u00e0o n\u00fat \u0111i\u1ec1u khi\u1ec3n v\u00e0 th\u1ef1c thi t\u1eadp l\u1ec7nh n\u00fat \u0111i\u1ec1u khi\u1ec3n,&nbsp;<code>ansibleCN_setup.sh<\/code>.<\/p>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: Trong t\u1ea5t c\u1ea3 c\u00e1c b\u01b0\u1edbc trong ph\u1ea7n n\u00e0y, h\u00e3y thay th\u1ebf&nbsp;<code>VM1_IPADDRESS<\/code>b\u1eb1ng&nbsp;<a href=\"https:\/\/www.linode.com\/docs\/products\/compute\/compute-instances\/guides\/manage-ip-addresses\/\">\u0111\u1ecba ch\u1ec9 IP<\/a>&nbsp;l\u1ea5y \u0111\u01b0\u1ee3c t\u1eeb Linode CLI ho\u1eb7c Cloud Manager.<\/p>\n<p class=\"has-background\" style=\"background-color:#f32a2a33\">Quan tr\u1ecdng: \u0110\u1eebng qu\u00ean d\u1ea5u hai ch\u1ea5m \u201c&nbsp;<strong>:<\/strong>&nbsp;\u201d \u1edf cu\u1ed1i l\u1ec7nh b\u00ean d\u01b0\u1edbi.<\/p>\n<pre class=\"wp-block-code\"><code>scp ansibleCN_setup.sh ansibleMN_setup.sh myplaybook.yml root@VM1_IPADDRESS:<\/code><\/pre>\n<h3 id=\"update-secure-and-install-package-dependencies-on-the-linode\">C\u1eadp nh\u1eadt, b\u1ea3o m\u1eadt v\u00e0 c\u00e0i \u0111\u1eb7t c\u00e1c g\u00f3i ph\u1ee5 thu\u1ed9c tr\u00ean Linode<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#update-secure-and-install-package-dependencies-on-the-linode\"><\/a><\/h3>\n<p>1.SSH v\u00e0o&nbsp;<code>vm1<\/code>v\u00e0 ch\u1ea1y&nbsp;<code>ansibleCN_setup.sh<\/code>. Thao t\u00e1c n\u00e0y s\u1ebd c\u1eadp nh\u1eadt, b\u1ea3o m\u1eadt v\u00e0 c\u00e0i \u0111\u1eb7t ch\u1ec9 nh\u1eefng ph\u1ee5 thu\u1ed9c c\u1ea7n thi\u1ebft tr\u00ean Linode.<code> <\/code><\/p>\n<pre class=\"wp-block-code\"><code><code>ssh root@VM1_IPADDRESS<\/code><\/code><\/pre>\n<p>2.Thay \u0111\u1ed5i quy\u1ec1n tr\u00ean&nbsp;<code>ansibleCN_setup.sh<\/code>v\u00e0&nbsp;<code>ansibleMN_setup.sh<\/code>\u0111\u1ec3 c\u00f3 th\u1ec3 th\u1ef1c thi.<code> <\/code><\/p>\n<pre class=\"wp-block-code\"><code>chmod 744 ansibleCN_setup.sh ansibleMN_setup.sh\n<\/code><\/pre>\n<p>3.Th\u1ef1c&nbsp;<code>ansibleCN_setup.sh<\/code>thi t\u1eadp l\u1ec7nh. Ph\u1ea3i m\u1ea5t v\u00e0i ph\u00fat \u0111\u1ec3 t\u1eadp l\u1ec7nh ho\u00e0n t\u1ea5t.<code> <\/code><\/p>\n<pre class=\"wp-block-code\"><code><code>.\/ansibleCN_setup.sh<\/code><\/code><\/pre>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: T\u1eadp l\u1ec7nh y\u00eau c\u1ea7u b\u1ea1n nh\u1eadp t\u00ean ng\u01b0\u1eddi d\u00f9ng v\u00e0 m\u1eadt kh\u1ea9u cho ng\u01b0\u1eddi d\u00f9ng m\u1edbi \u0111ang \u0111\u01b0\u1ee3c t\u1ea1o.<\/p>\n<h3 id=\"reboot-and-access-your-ansible-linode\">Kh\u1edfi \u0111\u1ed9ng l\u1ea1i v\u00e0 truy c\u1eadp Ansible Linode c\u1ee7a b\u1ea1n<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#reboot-and-access-your-ansible-linode\"><\/a><\/h3>\n<p>S\u1eed d\u1ee5ng l\u1ec7nh b\u00ean d\u01b0\u1edbi \u0111\u1ec3 kh\u1edfi \u0111\u1ed9ng l\u1ea1i Linode b\u1eb1ng c\u00e1ch s\u1eed d\u1ee5ng Linode CLI. B\u1ea1n c\u0169ng c\u00f3 th\u1ec3 kh\u1edfi \u0111\u1ed9ng l\u1ea1i Linode b\u1eb1ng Cloud Manager.<\/p>\n<pre class=\"wp-block-code\"><code>linode-cli linodes reboot LINODE_ID\n<\/code><\/pre>\n<p>S\u1eed d\u1ee5ng l\u1ec7nh b\u00ean d\u01b0\u1edbi \u0111\u1ec3 SSH v\u00e0o&nbsp;<code>vm1<\/code>.<\/p>\n<p class=\"has-background\" style=\"background-color:#f32a2a33\">Quan tr\u1ecdngH\u00e3y ch\u1eafc ch\u1eafn s\u1eed d\u1ee5ng ng\u01b0\u1eddi d\u00f9ng m\u1edbi m\u00e0 b\u1ea1n \u0111\u00e3 t\u1ea1o v\u00ec t\u1eadp l\u1ec7nh thi\u1ebft l\u1eadp s\u1ebd v\u00f4 hi\u1ec7u h\u00f3a ch\u1ee9c n\u0103ng \u0111\u0103ng nh\u1eadp root.<\/p>\n<pre class=\"wp-block-code\"><code>ssh YOUR_USERNAME@VM1_IPADDRESS\n<\/code><\/pre>\n<p>B\u1ea1n s\u1ebd th\u1ea5y t\u00ean m\u00e1y ch\u1ee7,&nbsp;<strong>CtlNode<\/strong>&nbsp;, \u0111\u01b0\u1ee3c c\u1ea5u h\u00ecnh tr\u00ean d\u1ea5u nh\u1eafc l\u1ec7nh c\u00f9ng v\u1edbi t\u00ean ng\u01b0\u1eddi d\u00f9ng c\u1ee7a b\u1ea1n.<\/p>\n<pre class=\"wp-block-code\"><code>example_user@CtlNode:~$<\/code><\/pre>\n<h2 id=\"configure-your-control-node-to-connect-to-the-worker-nodes\">C\u1ea5u h\u00ecnh N\u00fat \u0111i\u1ec1u khi\u1ec3n c\u1ee7a b\u1ea1n \u0111\u1ec3 k\u1ebft n\u1ed1i v\u1edbi N\u00fat c\u00f4ng nh\u00e2n<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#configure-your-control-node-to-connect-to-the-worker-nodes\"><\/a><\/h2>\n<h3 id=\"set-up-your-control-nodes-hosts-file\">Thi\u1ebft l\u1eadp t\u1ec7p m\u00e1y ch\u1ee7 c\u1ee7a n\u00fat \u0111i\u1ec1u khi\u1ec3n c\u1ee7a b\u1ea1n<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#set-up-your-control-nodes-hosts-file\"><\/a><\/h3>\n<p>\u0110i\u1ec1u n\u00e0y cho ph\u00e9p b\u1ea1n s\u1eed d\u1ee5ng t\u00ean m\u00e1y ch\u1ee7 khi tham chi\u1ebfu \u0111\u1ebfn c\u00e1c phi\u00ean b\u1ea3n kh\u00e1c nhau. Ch\u1ea1y l\u1ec7nh b\u00ean d\u01b0\u1edbi t\u1eeb m\u00e1y c\u1ee5c b\u1ed9 c\u1ee7a b\u1ea1n.<\/p>\n<pre class=\"wp-block-code\"><code>linode-cli linodes list --text | grep vm | awk '{print $7,$2,$2\".ansi.com\"}' | column -t\n<\/code><\/pre>\n<p>\u0110\u1ea7u ra c\u1ee7a b\u1ea1n s\u1ebd gi\u1ed1ng nh\u01b0 v\u00ed d\u1ee5 sau:<\/p>\n<pre class=\"wp-block-code\"><code>192.0.2.0  vm1  vm1.ansi.com\n192.0.2.1  vm2  vm2.ansi.com\n192.0.2.2  vm3  vm3.ansi.com\n192.0.2.3   vm4  vm4.ansi.com\n192.0.2.4  vm5  vm5.ansi.com<\/code><\/pre>\n<p>S\u1eed d\u1ee5ng tr\u00ecnh so\u1ea1n th\u1ea3o v\u0103n b\u1ea3n b\u1ea1n ch\u1ecdn, sao ch\u00e9p v\u00e0 d\u00e1n \u0111\u1ea7u ra n\u00e0y v\u00e0o cu\u1ed1i&nbsp;<code>\/etc\/hosts\/<\/code>t\u1ec7p tr\u00ean&nbsp;<code>vm1<\/code>.<\/p>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: S\u1eed d\u1ee5ng&nbsp;<code>sudo<\/code>\u0111\u1ec3 ch\u1ec9nh s\u1eeda&nbsp;<code>\/etc\/hosts<\/code>b\u1eb1ng Vi(m).<\/p>\n<p>S\u1eed d\u1ee5ng d\u00f2ng m\u00e3 b\u00ean d\u01b0\u1edbi \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o b\u1ea1n c\u00f3 th\u1ec3 ping t\u1ea5t c\u1ea3 t\u00ean m\u00e1y ch\u1ee7.<\/p>\n<pre class=\"wp-block-code\"><code>for i in {1..5}; do ping -c 2 vm$i; done<\/code><\/pre>\n<h2 id=\"create-ansible-configs-on-the-control-node\">T\u1ea1o Ansible Configs tr\u00ean Control Node<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#create-ansible-configs-on-the-control-node\"><\/a><\/h2>\n<p>S\u1eed d\u1ee5ng tr\u00ecnh so\u1ea1n th\u1ea3o v\u0103n b\u1ea3n, t\u1ea1o v\u00e0 sao ch\u00e9p t\u1ec7p c\u1ea5u h\u00ecnh,&nbsp;<code>ansible.cfg<\/code>, v\u00e0o th\u01b0 m\u1ee5c g\u1ed1c c\u1ee7a b\u1ea1n.<\/p>\n<pre class=\"wp-block-code\"><code>&#91;defaults]\ninventory = $HOME\/hosts<\/code><\/pre>\n<p>T\u1ea1o v\u00e0 sao ch\u00e9p t\u1ec7p c\u1ea5u h\u00ecnh m\u00e1y ch\u1ee7 Ansible b\u00ean d\u01b0\u1edbi v\u00e0o th\u01b0 m\u1ee5c g\u1ed1c c\u1ee7a b\u1ea1n.<\/p>\n<pre class=\"wp-block-code\"><code> &#91;webservers]\n vm2\n vm3\n\n &#91;dbservers]\n vm4\n\n &#91;logservers]\n vm5\n\n &#91;lamp:children]\n webservers\n dbservers<\/code><\/pre>\n<p>S\u1eed d\u1ee5ng l\u1ec7nh b\u00ean d\u01b0\u1edbi \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o t\u1ea5t c\u1ea3 m\u00e1y ch\u1ee7 \u0111\u1ec1u c\u00f3 th\u1ec3 truy c\u1eadp \u0111\u01b0\u1ee3c.<\/p>\n<pre class=\"wp-block-code\"><code>ansible all --list-hosts\n<\/code><\/pre>\n<p>\u0110\u1ea7u ra c\u1ee7a b\u1ea1n s\u1ebd gi\u1ed1ng nh\u01b0 sau:<\/p>\n<pre class=\"wp-block-code\"><code>example_user@CtlNode:~$ ansible all --list-hosts\n  hosts (4):\n    vm5\n    vm2\n    vm3\n    vm4<\/code><\/pre>\n<h2 id=\"set-up-ansible-playbook-to-configure-worker-nodes\">Thi\u1ebft l\u1eadp Ansible Playbook \u0111\u1ec3 c\u1ea5u h\u00ecnh c\u00e1c n\u00fat Worker<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#set-up-ansible-playbook-to-configure-worker-nodes\"><\/a><\/h2>\n<h3 id=\"create-and-add-hashed-plain-text-password-to-ansible-playbook\">T\u1ea1o v\u00e0 th\u00eam m\u1eadt kh\u1ea9u b\u0103m, d\u1ea1ng v\u0103n b\u1ea3n thu\u1ea7n t\u00fay v\u00e0o Ansible Playbook<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#create-and-add-hashed-plain-text-password-to-ansible-playbook\"><\/a><\/h3>\n<p>Ch\u1ea1y l\u1ec7nh b\u00ean d\u01b0\u1edbi t\u1eeb n\u00fat \u0111i\u1ec1u khi\u1ec3n Ansible c\u1ee7a b\u1ea1n. L\u1ec7nh s\u1ebd nh\u1eafc b\u1ea1n nh\u1eadp m\u1eadt kh\u1ea9u. M\u1eadt kh\u1ea9u n\u00e0y \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 truy c\u1eadp v\u00e0o m\u00e1y ch\u1ee7 web.<\/p>\n<pre class=\"wp-block-code\"><code> python3 -c \"from passlib.hash import sha512_crypt; import getpass; print(sha512_crypt.hash(getpass.getpass()))\"\n<\/code><\/pre>\n<p>H\u00e3y \u0111\u1ea3m b\u1ea3o sao ch\u00e9p \u0111\u1ea7u ra t\u1eeb d\u1ea5u \u0111\u00f4 la \u0111\u1ebfn d\u1ea5u ch\u1ea5m. D\u00e1n m\u1eadt kh\u1ea9u \u0111\u00e3 b\u0103m k\u1ebft qu\u1ea3 v\u00e0o&nbsp;<code>myplaybook.yml<\/code>, trong ch\u1ed7 gi\u1eef ch\u1ed7,&nbsp;<strong>{{ HASHED_PASSWORD }}<\/strong>&nbsp;.<\/p>\n<h3 id=\"add-your-log-server-ip-address-to-playbook\">Th\u00eam \u0110\u1ecba ch\u1ec9 IP M\u00e1y ch\u1ee7 Nh\u1eadt k\u00fd c\u1ee7a b\u1ea1n v\u00e0o Playbook<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#add-your-log-server-ip-address-to-playbook\"><\/a><\/h3>\n<p>L\u1ea5y \u0111\u1ecba ch\u1ec9 IP c\u1ee7a m\u00e1y ch\u1ee7 ghi nh\u1eadt k\u00fd (&nbsp;<code>vm5<\/code>) v\u00e0 d\u00e1n v\u00e0o&nbsp;<code>configure rsyslog<\/code>ph\u1ea7n&nbsp;<code>myplaybook.yml<\/code>. D\u00e1n \u0111\u1ecba ch\u1ec9 IP v\u00e0o ch\u1ed7 gi\u1eef ch\u1ed7,&nbsp;<strong>{{ LOG_IP_ADDRESS }}<\/strong>&nbsp;.<\/p>\n<h2 id=\"configure-ansible-managed-nodes\">C\u1ea5u h\u00ecnh c\u00e1c n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd c\u1ee7a Ansible<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#configure-ansible-managed-nodes\"><\/a><\/h2>\n<h3 id=\"send-setup-script-to-each-managed-node\">G\u1eedi t\u1eadp l\u1ec7nh thi\u1ebft l\u1eadp \u0111\u1ebfn t\u1eebng n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#send-setup-script-to-each-managed-node\"><\/a><\/h3>\n<p>T\u1ea1o m\u1ed9t t\u1ec7p m\u1eadt kh\u1ea9u \u0111\u1ec3 s\u1eed d\u1ee5ng \u1edf b\u01b0\u1edbc ti\u1ebfp theo. S\u1eed d\u1ee5ng c\u00f9ng m\u1eadt kh\u1ea9u g\u1ed1c m\u00e0 b\u1ea1n \u0111\u00e3 d\u00f9ng khi t\u1ea1o c\u00e1c Linode n\u00e0y.<\/p>\n<pre class=\"wp-block-code\"><code>echo 'yourrootpassword' &gt; ~\/.ssh\/file\n<\/code><\/pre>\n<p>G\u1eedi t\u1eadp l\u1ec7nh thi\u1ebft l\u1eadp n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd t\u1edbi t\u1eebng n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd.<\/p>\n<pre class=\"wp-block-code\"><code>for i in {2..5}; do sshpass -f ~\/.ssh\/file scp ansibleMN_setup.sh root@vm$i:\/root\/; done\n<\/code><\/pre>\n<p>Ki\u1ec3m tra \u0111\u1ec3 \u0111\u1ea3m b\u1ea3o m\u1ed7i n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd \u0111\u1ec1u ch\u1ee9a t\u1eadp l\u1ec7nh b\u1eb1ng c\u00e1ch g\u1eedi&nbsp;<code>ls<\/code>l\u1ec7nh qua ssh.<\/p>\n<pre class=\"wp-block-code\"><code>for i in {2..5}; do sshpass -f ~\/.ssh\/file ssh root@vm$i 'ls'; done\n<\/code><\/pre>\n<p>K\u1ebft qu\u1ea3 \u0111\u1ea7u ra nh\u01b0 sau:<\/p>\n<pre class=\"wp-block-code\"><code>example_user@CtlNode:~$ for i in {2..5}; do sshpass -f ~\/.ssh\/file ssh root@vm$i 'ls'; done\nansibleMN_setup.sh\nansibleMN_setup.sh\nansibleMN_setup.sh\nansibleMN_setup.sh<\/code><\/pre>\n<h3 id=\"log-into-each-worker-node-and-run-the-setup-script\">\u0110\u0103ng nh\u1eadp v\u00e0o t\u1eebng n\u00fat Worker v\u00e0 ch\u1ea1y t\u1eadp l\u1ec7nh thi\u1ebft l\u1eadp<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#log-into-each-worker-node-and-run-the-setup-script\"><\/a><\/h3>\n<p>T\u1eeb m\u00e1y t\u00ednh c\u1ee5c b\u1ed9, m\u1edf b\u1ed1n phi\u00ean thi\u1ebft b\u1ecb \u0111\u1ea7u cu\u1ed1i v\u00e0 trong m\u1ed7i phi\u00ean, ssh v\u00e0o t\u1eebng n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd (&nbsp;<code>vm2<\/code>&#8211;&nbsp;<code>vm5<\/code>). Sau khi \u0111\u0103ng nh\u1eadp, h\u00e3y th\u1ef1c thi t\u1eadp l\u1ec7nh thi\u1ebft l\u1eadp n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd.<\/p>\n<pre class=\"wp-block-code\"><code>.\/ansibleMN_setup.sh\n<\/code><\/pre>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: T\u1eadp l\u1ec7nh y\u00eau c\u1ea7u b\u1ea1n nh\u1eadp t\u00ean ng\u01b0\u1eddi d\u00f9ng v\u00e0 m\u1eadt kh\u1ea9u cho ng\u01b0\u1eddi d\u00f9ng m\u1edbi \u0111ang \u0111\u01b0\u1ee3c t\u1ea1o.<\/p>\n<p>Sau khi t\u1eadp l\u1ec7nh thi\u1ebft l\u1eadp ho\u00e0n t\u1ea5t cho t\u1eebng n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd, h\u00e3y kh\u1edfi \u0111\u1ed9ng l\u1ea1i t\u1ea5t c\u1ea3 c\u00e1c Linode c\u01a1 s\u1edf h\u1ea1 t\u1ea7ng Ansible c\u1ee7a b\u1ea1n b\u1eb1ng l\u1ec7nh b\u00ean d\u01b0\u1edbi.<\/p>\n<pre class=\"wp-block-code\"><code>for i in $(cat tmp.txt); do linode-cli linodes reboot $i; done\n<\/code><\/pre>\n<h3 id=\"upload-the-ssh-key-from-the-control-node-to-the-managed-nodes\">T\u1ea3i Kh\u00f3a SSH t\u1eeb N\u00fat \u0110i\u1ec1u khi\u1ec3n l\u00ean c\u00e1c N\u00fat \u0110\u01b0\u1ee3c Qu\u1ea3n l\u00fd<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#upload-the-ssh-key-from-the-control-node-to-the-managed-nodes\"><\/a><\/h3>\n<p>\u0110\u0103ng nh\u1eadp l\u1ea1i v\u00e0o n\u00fat \u0111i\u1ec1u khi\u1ec3n v\u00e0 ch\u1ea1y l\u1ec7nh b\u00ean d\u01b0\u1edbi. L\u1ec7nh n\u00e0y s\u1ebd g\u1eedi kh\u00f3a ssh c\u1ee7a ng\u01b0\u1eddi d\u00f9ng gi\u1edbi h\u1ea1n c\u1ee7a n\u00fat \u0111i\u1ec1u khi\u1ec3n \u0111\u1ebfn t\u1eebng n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd. L\u1ec7nh n\u00e0y cho ph\u00e9p giao ti\u1ebfp ssh d\u1ec5 d\u00e0ng v\u00e0 an to\u00e0n t\u1eeb n\u00fat \u0111i\u1ec1u khi\u1ec3n \u0111\u1ebfn c\u00e1c n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd.<\/p>\n<pre class=\"wp-block-code\"><code>for i in {2..5}; do sshpass -f ~\/.ssh\/file ssh-copy-id $USER@vm$i; done\n<\/code><\/pre>\n<p class=\"has-background\" style=\"background-color:#74f78c33\">Ghi ch\u00fa: N\u1ebfu m\u1eadt kh\u1ea9u c\u1ee7a ng\u01b0\u1eddi d\u00f9ng b\u1ecb gi\u1edbi h\u1ea1n kh\u00e1c v\u1edbi m\u1eadt kh\u1ea9u c\u1ee7a ng\u01b0\u1eddi d\u00f9ng g\u1ed1c, h\u00e3y thay \u0111\u1ed5i&nbsp;<code>~\/.ssh\/file<\/code>n\u1ed9i dung cho kh\u1edbp v\u1edbi m\u1eadt kh\u1ea9u c\u1ee7a ng\u01b0\u1eddi d\u00f9ng b\u1ecb gi\u1edbi h\u1ea1n.<\/p>\n<p>X\u00e1c nh\u1eadn t\u1ea5t c\u1ea3 c\u00e1c m\u00e1y ch\u1ee7 c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c ping b\u1eb1ng Ansible. Ch\u1ea1y th\u00e0nh c\u00f4ng l\u1ec7nh n\u00e0y cho bi\u1ebft&nbsp;<a href=\"https:\/\/docs.ansible.com\/ansible\/2.7\/user_guide\/intro_getting_started.html#remote-connection-information\" target=\"_blank\" rel=\"noreferrer noopener\">giao ti\u1ebfp ssh \u0111ang ho\u1ea1t \u0111\u1ed9ng.<\/a><\/p>\n<pre class=\"wp-block-code\"><code>ansible all -m ping\n<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>example_user@CtlNode:~$ ansible all -m ping\nvm4 | SUCCESS =&gt; {\n    \"ansible_facts\": {\n        \"discovered_interpreter_python\": \"\/usr\/bin\/python3\"\n    },\n    \"changed\": false,\n    \"ping\": \"pong\"\n}\nvm3 | SUCCESS =&gt; {\n    \"ansible_facts\": {\n        \"discovered_interpreter_python\": \"\/usr\/bin\/python3\"\n    },\n    \"changed\": false,\n    \"ping\": \"pong\"\n}\nvm2 | SUCCESS =&gt; {\n    \"ansible_facts\": {\n        \"discovered_interpreter_python\": \"\/usr\/bin\/python3\"\n    },\n    \"changed\": false,\n    \"ping\": \"pong\"\n}\nvm5 | SUCCESS =&gt; {\n    \"ansible_facts\": {\n        \"discovered_interpreter_python\": \"\/usr\/bin\/python3\"\n    },\n    \"changed\": false,\n    \"ping\": \"pong\"\n}<\/code><\/pre>\n<h2 id=\"run-the-ansible-playbook-to-configure-managed-nodes\">Ch\u1ea1y Ansible Playbook \u0111\u1ec3 c\u1ea5u h\u00ecnh c\u00e1c n\u00fat \u0111\u01b0\u1ee3c qu\u1ea3n l\u00fd<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#run-the-ansible-playbook-to-configure-managed-nodes\"><\/a><\/h2>\n<p>Ch\u1ea1y playbook b\u1eb1ng l\u1ec7nh b\u00ean d\u01b0\u1edbi:<\/p>\n<pre class=\"wp-block-code\"><code>ansible-playbook myplaybook.yml\n<\/code><\/pre>\n<p>N\u1ebfu m\u1ecdi th\u1ee9 \u0111\u1ec1u th\u00e0nh c\u00f4ng, b\u1ea1n s\u1ebd th\u1ea5y k\u1ebft qu\u1ea3 \u0111\u01b0\u1ee3c \u0111\u01b0a ra b\u00ean d\u01b0\u1edbi. L\u01b0u \u00fd r\u1eb1ng&nbsp;<code>unreachable<\/code>v\u00e0&nbsp;<code>failed<\/code>c\u1ea3 hai \u0111\u1ec1u hi\u1ec3n th\u1ecb&nbsp;<code>0<\/code>c\u00e1c tr\u01b0\u1eddng h\u1ee3p.<\/p>\n<p>\u0110\u1ea7u ra b\u1ecb c\u1eaft b\u1edbt:<\/p>\n<pre class=\"wp-block-code\"><code>example_user@CtlNode:~$ ansible-playbook myplaybook.yml\n\nPLAY &#91;webservers] *************************************************************************************************\n\nTASK &#91;Gathering Facts] ********************************************************************************************\nok: &#91;vm3]\nok: &#91;vm2]\n\nTASK &#91;Install Apache Server] **************************************************************************************\nchanged: &#91;vm3]\nchanged: &#91;vm2]\n\n{ ... }\n\nPLAY RECAP ********************************************************************************************************\nvm2                        : ok=13   changed=9    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0\nvm3                        : ok=13   changed=9    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0\nvm4                        : ok=6    changed=3    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0\nvm5                        : ok=6    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0<\/code><\/pre>\n<h2 id=\"check-the-playbook-run-for-success\">Ki\u1ec3m tra Playbook Ch\u1ea1y \u0111\u1ec3 th\u00e0nh c\u00f4ng<a href=\"https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/#check-the-playbook-run-for-success\"><\/a><\/h2>\n<p>cURL \u0111\u1ecba ch\u1ec9 IP c\u1ee7a m\u00e1y ch\u1ee7 web. (&nbsp;<code>vm2<\/code>v\u00e0&nbsp;<code>vm3<\/code>)<\/p>\n<pre class=\"wp-block-code\"><code>curl vm2_IPADDRESS\ncurl vm3_IPADDRESS\n<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>example_user@CtlNode:~$ curl 192.0.2.1\nWelcome to li1924-155 on 192.0.2.1\n\nexample_user@CtlNode:~$ curl 192.0.2.2\nWelcome to li1924-165 on 192.0.2.2<\/code><\/pre>\n<p>G\u1eedi&nbsp;<code>logger<\/code>l\u1ec7nh \u0111\u1ebfn ng\u0103n x\u1ebfp LAMP \u0111\u01b0\u1ee3c x\u00e1c \u0111\u1ecbnh trong&nbsp;<code>hosts<\/code>t\u1ec7p.<\/p>\n<pre class=\"wp-block-code\"><code>ansible lamp -m command -a 'logger hurray it works'\n<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>example_user@CtlNode:~$ ansible lamp -m command -a 'logger hurray it works'\nvm4 | CHANGED | rc=0 &gt;&gt;\n\nvm3 | CHANGED | rc=0 &gt;&gt;\n\nvm2 | CHANGED | rc=0 &gt;&gt;<\/code><\/pre>\n<p>T\u00ecm ki\u1ebfm m\u1ee5c nh\u1eadp b\u1ea1n v\u1eeba g\u1eedi tr\u00ean m\u00e1y ch\u1ee7 nh\u1eadt k\u00fd.<\/p>\n<pre class=\"wp-block-code\"><code>ansible logservers -m command -a \"grep 'hurray it works$' \/var\/log\/syslog\" -b\n<\/code><\/pre>\n<pre class=\"wp-block-code\"><code>example_user@CtlNode:~$ ansible logservers -m command -a \"grep 'hurray it works$' \/var\/log\/syslog\" -b\nvm5 | CHANGED | rc=0 &gt;&gt;\nOct 25 21:22:00 li1924-200 example_user: hurray it works\nOct 25 21:22:00 li1924-165 example_user: hurray it works\nOct 25 21:22:00 li1924-155 example_user: hurray it works<\/code><\/pre>\n<p>B\u00e2y gi\u1edd b\u1ea1n \u0111\u00e3 ho\u00e0n t\u1ea5t vi\u1ec7c tri\u1ec3n khai m\u00e1y ch\u1ee7 web, m\u00e1y ch\u1ee7 nh\u1eadt k\u00fd v\u00e0 m\u00e1y ch\u1ee7 c\u01a1 s\u1edf d\u1eef li\u1ec7u b\u1eb1ng Ansible.<\/p>\n<h2 id=\"more-information\">Th\u00f4ng tin th\u00eam<\/h2>\n<p>B\u1ea1n c\u00f3 th\u1ec3 mu\u1ed1n tham kh\u1ea3o c\u00e1c ngu\u1ed3n sau \u0111\u1ec3 bi\u1ebft th\u00eam th\u00f4ng tin v\u1ec1 ch\u1ee7 \u0111\u1ec1 n\u00e0y. M\u1eb7c d\u00f9 ch\u00fang t\u00f4i cung c\u1ea5p v\u1edbi hy v\u1ecdng r\u1eb1ng ch\u00fang s\u1ebd h\u1eefu \u00edch, nh\u01b0ng xin l\u01b0u \u00fd r\u1eb1ng ch\u00fang t\u00f4i kh\u00f4ng th\u1ec3 \u0111\u1ea3m b\u1ea3o t\u00ednh ch\u00ednh x\u00e1c ho\u1eb7c t\u00ednh k\u1ecbp th\u1eddi c\u1ee7a c\u00e1c t\u00e0i li\u1ec7u \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef b\u00ean ngo\u00e0i.<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/index.html\" target=\"_blank\" rel=\"noreferrer noopener\">H\u01b0\u1edbng d\u1eabn s\u1eed d\u1ee5ng Ansible<\/a><\/li>\n<li><a href=\"https:\/\/docs.ansible.com\/ansible\/latest\/user_guide\/playbooks_intro.html\" target=\"_blank\" rel=\"noreferrer noopener\">Gi\u1edbi thi\u1ec7u v\u1ec1 Ansible Playbooks<\/a><\/li>\n<\/ul>\n<p>Ngu\u1ed3n: https:\/\/www.linode.com\/docs\/guides\/use-ansible-to-automate-web-server-infrastructure\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ansible l\u00e0 g\u00ec? Ansible l\u00e0 m\u1ed9t c\u00f4ng c\u1ee5 cung c\u1ea5p ph\u1ea7n m\u1ec1m m\u00e3 ngu\u1ed3n m\u1edf t\u1ef1 \u0111\u1ed9ng h\u00f3a vi\u1ec7c tri\u1ec3n khai \u1ee9ng d\u1ee5ng v\u00e0 c\u01a1 s\u1edf h\u1ea1 t\u1ea7ng CNTT. N\u00f3 nh\u1eb9 v\u00e0 kh\u00f4ng c\u00f3 t\u00e1c nh\u00e2n, ngh\u0129a l\u00e0 kh\u00f4ng c\u1ea7n c\u00e0i \u0111\u1eb7t ph\u1ea7n m\u1ec1m m\u00e1y kh\u00e1ch ho\u1eb7c m\u00e1y ch\u1ee7. Ansible s\u1eed d\u1ee5ng SSH v\u00e0 Python<\/p>\n","protected":false},"author":1,"featured_media":35680,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[129],"tags":[],"class_list":["post-34918","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ansible"],"_links":{"self":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/posts\/34918","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/comments?post=34918"}],"version-history":[{"count":0,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/posts\/34918\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/media\/35680"}],"wp:attachment":[{"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/media?parent=34918"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/categories?post=34918"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jupitek.maudemo.vip\/index.php\/wp-json\/wp\/v2\/tags?post=34918"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}