Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------ Additional task -------------------------------------------------
- ---
- - name: "Provisioning the tesla-infra using ansible+terraform"
- hosts: localhost
- become: true
- vars:
- terraform_amd64: https://releases.hashicorp.com/terraform/1.5.2/terraform_1.5.2_linux_amd64.zip
- tasks:
- - name: "get_url the terraform binary download"
- get_url:
- url: "{{ terraform_amd64 }}"
- dest: /tmp/url.zip
- - name: "Unarchive the zip file"
- unarchive:
- src: /tmp/url.zip
- dest: /usr/local/bin/
- - name: "Ansible Terraform module install"
- community.general.ansible_galaxy_install:
- type: collection
- name: community.general
- - name: "Cleanup Terraform installation in ansible master machine"
- file:
- path: /tmp/url.zip
- state: absent
- - name: "Terraform deployment of Tesla infra"
- community.general.terraform:
- project_path: ./tesla-infra
- state: present
- force_init: true
- register: terraform_status
- - name: "Printing the terraform servers private ip"
- debug:
- msg: "{{ item }}"
- with_items:
- - "{{ terraform_status.outputs.private_ips.value }}"
- - name: "Creating a dynamic inventory"
- add_host:
- hostname: "{{ item }}"
- groups: Tesla-infra
- ansible_ssh_host: "{{ item }}"
- ansible_ssh_user: ec2-user
- ansible_ssh_private_key_file: ./aws.pem
- ansible_ssh_common_args: "-o StrictHostKeyChecking=no"
- with_items:
- - "{{ terraform_status.outputs.private_ips.value }}"
- - name: "Provisioning a php website"
- hosts: Tesla-infra
- become: true
- serial: 1
- vars:
- packages:
- - httpd
- - php-fpm
- - git
- httpd_port: 80
- httpd_site: blog.chrisich.fun
- httpd_owner: apache
- httpd_group: apache
- repo_url: https://github.com/Chris-luiz-16/aws-elb-site.git
- tasks:
- - name: "Installing required packages for the website"
- yum:
- name: "{{ packages }}"
- state: present
- notify:
- - httpd-restart
- - php-restart
- - name: "Copying the httpd.conf.tmpl to /etc/httpd/conf/httpd.conf"
- template:
- src: ./httpd.conf.tmpl
- dest: /etc/httpd/conf/httpd.conf
- notify:
- - httpd-restart
- - name: "Copying the virtaulhost of {{ httpd_site }} to /etc/httpd/conf.d/{{ httpd_site }}"
- template:
- src: ./virtual.conf.tmpl
- dest: "/etc/httpd/conf.d/{{ httpd_site }}.conf"
- notify:
- - httpd-restart
- - name: "Cloning the website to the remote server"
- git:
- repo: "{{ repo_url }}"
- dest: /var/website/
- register: git_status
- - name: "Copying the website to the documentroot /var/www/html/{{ httpd_site }}/"
- when: git_status.changed == true
- copy:
- src: /var/website/
- dest: "/var/www/html/{{ httpd_site }}/"
- owner: "{{ httpd_owner }}"
- group: "{{ httpd_group }}"
- remote_src: true
- notify:
- - php-restart
- handlers:
- - name: "httpd-restart"
- service:
- name: httpd
- state: restarted
- enabled: true
- - name: "php-restart"
- service:
- name: php-fpm
- state: restarted
- enabled: true
- #### Output ####
- [ec2-user@ip-172-31-33-5 test-project]$ ansible-playbook main.yml
- [WARNING]: No inventory was parsed, only implicit localhost is available
- [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
- PLAY [Provisioning the tesla-infra using ansible+terraform] ************************************************************************************************
- TASK [Gathering Facts] *************************************************************************************************************************************
- ok: [localhost]
- TASK [get_url the terraform binary download] ***************************************************************************************************************
- changed: [localhost]
- TASK [Unarchive the zip file] ******************************************************************************************************************************
- ok: [localhost]
- TASK [Ansible Terraform module install] ********************************************************************************************************************
- ok: [localhost]
- TASK [Cleanup Terraform installation in ansible master machine] ********************************************************************************************
- changed: [localhost]
- TASK [Terraform deployment of Tesla infra] *****************************************************************************************************************
- ok: [localhost]
- TASK [Printing the terraform servers private ip] ***********************************************************************************************************
- ok: [localhost] => (item=172.31.35.102) => {
- "msg": "172.31.35.102"
- }
- ok: [localhost] => (item=172.31.46.233) => {
- "msg": "172.31.46.233"
- }
- ok: [localhost] => (item=172.31.33.85) => {
- "msg": "172.31.33.85"
- }
- TASK [Creating a dynamic inventory] ************************************************************************************************************************
- changed: [localhost] => (item=172.31.35.102)
- changed: [localhost] => (item=172.31.46.233)
- changed: [localhost] => (item=172.31.33.85)
- PLAY [Provisioning a php website] **************************************************************************************************************************
- TASK [Gathering Facts] *************************************************************************************************************************************
- ok: [172.31.35.102]
- TASK [Installing required packages for the website] ********************************************************************************************************
- changed: [172.31.35.102]
- TASK [Copying the httpd.conf.tmpl to /etc/httpd/conf/httpd.conf] *******************************************************************************************
- changed: [172.31.35.102]
- TASK [Copying the virtaulhost of blog.chrisich.fun to /etc/httpd/conf.d/blog.chrisich.fun] *****************************************************************
- changed: [172.31.35.102]
- TASK [Cloning the website to the remote server] ************************************************************************************************************
- changed: [172.31.35.102]
- TASK [Copying the website to the documentroot /var/www/html/blog.chrisich.fun/] ****************************************************************************
- changed: [172.31.35.102]
- RUNNING HANDLER [httpd-restart] ****************************************************************************************************************************
- changed: [172.31.35.102]
- RUNNING HANDLER [php-restart] ******************************************************************************************************************************
- changed: [172.31.35.102]
- PLAY [Provisioning a php website] **************************************************************************************************************************
- TASK [Gathering Facts] *************************************************************************************************************************************
- ok: [172.31.46.233]
- TASK [Installing required packages for the website] ********************************************************************************************************
- changed: [172.31.46.233]
- TASK [Copying the httpd.conf.tmpl to /etc/httpd/conf/httpd.conf] *******************************************************************************************
- changed: [172.31.46.233]
- TASK [Copying the virtaulhost of blog.chrisich.fun to /etc/httpd/conf.d/blog.chrisich.fun] *****************************************************************
- changed: [172.31.46.233]
- TASK [Cloning the website to the remote server] ************************************************************************************************************
- changed: [172.31.46.233]
- TASK [Copying the website to the documentroot /var/www/html/blog.chrisich.fun/] ****************************************************************************
- changed: [172.31.46.233]
- RUNNING HANDLER [httpd-restart] ****************************************************************************************************************************
- changed: [172.31.46.233]
- RUNNING HANDLER [php-restart] ******************************************************************************************************************************
- changed: [172.31.46.233]
- PLAY [Provisioning a php website] **************************************************************************************************************************
- TASK [Gathering Facts] *************************************************************************************************************************************
- .
- ok: [172.31.33.85]
- TASK [Installing required packages for the website] ********************************************************************************************************
- changed: [172.31.33.85]
- TASK [Copying the httpd.conf.tmpl to /etc/httpd/conf/httpd.conf] *******************************************************************************************
- changed: [172.31.33.85]
- TASK [Copying the virtaulhost of blog.chrisich.fun to /etc/httpd/conf.d/blog.chrisich.fun] *****************************************************************
- changed: [172.31.33.85]
- TASK [Cloning the website to the remote server] ************************************************************************************************************
- changed: [172.31.33.85]
- TASK [Copying the website to the documentroot /var/www/html/blog.chrisich.fun/] ****************************************************************************
- changed: [172.31.33.85]
- RUNNING HANDLER [httpd-restart] ****************************************************************************************************************************
- changed: [172.31.33.85]
- RUNNING HANDLER [php-restart] ******************************************************************************************************************************
- changed: [172.31.33.85]
- PLAY RECAP *************************************************************************************************************************************************
- 172.31.33.85 : ok=8 changed=7 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- 172.31.35.102 : ok=8 changed=7 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- 172.31.46.233 : ok=8 changed=7 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- localhost : ok=8 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Advertisement
Add Comment
Please, Sign In to add comment