Shell script to make site https using certbot and nginx - shell

I know how to install ssl certificate using command-line. But i need a shell script this time to do this task.
Generally while doing this manually i first execute the fowllowing:-
sudo apt-get install certbot python-certbot-nginx
By executing the above i will be asked to continue or not?[Y/n]. I will enter 'Y'.Then i will execute the following command
sudo certbot --nginx
Executing the above will ask me to answer the following steps in ordered way:
Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel).
Agreement to Terms and Service [ (A)gree/(C)ancel: A ]
Consent to share development news and campaigns to my email address. [(Y)es/(N)o: N]
Which names would i like to activate HTTPS for? [Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): blank]
Redirection from http to https [Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2 ]
After doing all this steps https will be enabled. Now i need to do these things done programatically by shell file.I have figured out to install certbot and python-certbot-nginx using this
sudo apt-get install certbot python-certbot-nginx -y
But i do not know how to proceed further as i have never worked with shell scripts
PS: I am providing a sample result when i execute sudo certbot --nginx and enter details by myself.
sudo certbot --nginx
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): mygmailid#gmail.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: example.com
2: www.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for example.com
http-01 challenge for www.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/demowebsite.conf
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/demowebsite.conf
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/demowebsite.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/demowebsite.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled
https://example.com and
https://www.example.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=example.com
https://www.ssllabs.com/ssltest/analyze.html?d=www.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/example.com/privkey.pem
Your cert will expire on 2020-01-28. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

Though i am very late here but finally i did
as suggested by #JohnHanley in the comments. I went through the documentation and here is what i needed to execute the above mentioned steps in the question by command line.
run Obtain & install a certificate in your current webserver
-n Run without ever asking for user input. This may
require additional command line flags; the client will
try to explain which ones are required if it finds one
missing (default: False)
--nginx Obtain and install certificates using Nginx (default:False)
-d Domain names to apply. For multiple domains you can
use multiple -d flags or enter a comma separated list
of domains as a parameter. The first domain provided
will be the subject CN of the certificate, and all
domains will be Subject Alternative Names on the
certificate. The first domain will also be used in
some software user interfaces and as the file paths
for the certificate and related material unless
otherwise specified or you already have a certificate
with the same name. In the case of a name collision it
will append a number like 0001 to the file path name.
-m Email used for registration and recovery contact. Use
comma to register multiple emails, ex:
u1#example.com,u2#example.com. (default: Ask).
--redirect Automatically redirect all HTTP traffic to HTTPS for
the newly authenticated vhost. (default: Ask)
--agree-tos Agree to the ACME server's Subscriber Agreement
So the final command that i executed is below
certbot run -n --nginx --agree-tos -d example.com,www.example.com -m mygmailid#gmail.com --redirect

Related

Not able to install requirement s.txt file in my conda environment

I am trying to install a requirements.txt file to my conda environment, in Windows. Following are the steps followed:
Open Anaconda Prompt
conda activate new_env
Executing following command install requirments.txt files
conda install --file requirements.txt
This is the result I am getting.
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
PackagesNotFoundError: The following packages are not available from current channels:
- torchsummary==1.5.1
- prometheus-client
- opencv-python==4.5.4.58
- gviz-api==1.10.0
- jupyterlab-widgets==1.0.2
- psutil==5.9.2
- pycrs==1.0.2
- pyrsistent==0.18.1
- jupyterlab-pygments
- pytweening==1.0.4
- qudida==0.0.4
- pyscreeze==0.1.28
- smmap==5.0.0
- pygetwindow==0.0.9
- setproctitle==1.3.2
- torchvision==0.11.2
- opt-einsum==3.3.0
- fastjsonschema
- mahotas==1.4.12
- imageio==2.15.0
- cachetools==4.2.4
- tensorflow-gpu==2.7.0
- tensorflow-estimator==2.7.0
- tifffile==2021.11.2
- pyrect==0.1.4
- thop==0.1.1.post2209072238
- tensorboard-plugin-profile==2.8.0
- sentry-sdk==1.9.10
- ipython-genutils
- prompt-toolkit==3.0.27
- fonttools==4.28.5
- ctypes-callable==1.0.4
- importlib-resources==5.4.0
- tensorboard-data-server==0.6.1
- jupyter-console==6.4.0
- torch==1.10.1
- gitdb==4.0.9
- opencv-python-headless==4.5.5.62
- pywavelets==1.2.0
- pyproj==3.2.1
- win-inet-pton
- mouseinfo==0.1.3
- rsa==4.8
- keras==2.7.0
- pymsgbox==1.0.9
- pyperclip==1.8.2
- absl-py==1.0.0
- tensorflow-io-gcs-filesystem==0.23.1
- charset-normalizer==2.0.10
- threadpoolctl==3.1.0
- albumentations==1.1.0
- geojson
- gitpython==3.1.29
- markdown==3.3.6
- mkl-random
- mkl-fft==1.3.1
- tensorflow==2.7.0
- pkgutil_resolve_name
- scikit-image==0.19.1
- pyautogui==0.9.53
- bidict==0.21.4
- grpcio==1.43.0
- shortuuid==1.0.9
Current channels:
- https://repo.anaconda.com/pkgs/main/win-64
- https://repo.anaconda.com/pkgs/main/noarch
- https://repo.anaconda.com/pkgs/r/win-64
- https://repo.anaconda.com/pkgs/r/noarch
- https://repo.anaconda.com/pkgs/msys2/win-64
- https://repo.anaconda.com/pkgs/msys2/noarch
To search for alternate channels that may provide the conda package you're
looking for, navigate to
https://anaconda.org
and use the search bar at the top of the page.
What can be the issue?
Note: The folder path is set to the location where the 'requirements.txt' file is residing.
I have implemented it in Anconda, version 2022.05 on Windows 10.

SSL certificate installation using letsencrypt in XAMPP server

I'm using command:
sudo certbot --apache-ctl /opt/lampp/bin/apachectl
to install the certificate in XAMPP server. However the certificate is installing in the /etc/apache2 location.
How can I repoint to the XAMPP Apache server? The logs is below:
ubuntu#ip-172-31-33-70:~$ sudo certbot --apache-ctl /opt/lampp/bin/apachectl
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
No names were found in your configuration files. Please enter in your domain
name(s) (comma and/or space separated) (Enter 'c' to cancel): ploshop.co.in
Cert not yet due for renewal
You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.
(ref: /etc/letsencrypt/renewal/ploshop.co.in.conf)
What would you like to do?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Attempt to reinstall this existing certificate
2: Renew & replace the cert (limit ~5 per 7 days)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Renewing an existing certificate
Created an SSL vhost at /etc/apache2/sites-available/000-default-le-ssl.conf
Deploying Certificate to VirtualHost /etc/apache2/sites-available/000-default-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/000-default-le-ssl.conf
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting vhost in /etc/apache2/sites-enabled/000-default.conf to ssl vhost in /etc/apache2/sites-available/000-default-le-ssl.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Your existing certificate has been successfully renewed, and the new certificate
has been installed.
The new certificate covers the following domains: https://ploshop.co.in
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=ploshop.co.in
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/ploshop.co.in/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/ploshop.co.in/privkey.pem
Your cert will expire on 2021-11-17. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
ubuntu#ip-172-31-33-70:~$
Modify the locations based upon your installation. I am using the default paths.
Edit the file
Linux: /opt/lampp/apache/conf/extra/httpd-ssl.conf
Windows: /xampp/apache/conf/extra/httpd-ssl.conf
Locate the section that defines the port 443 listener:
Change this part:
<VirtualHost *:443>
...
SSLEngine on
SSLCertificateFile "conf/ssl.crt/server.crt"
SSLCertificateKeyFile "conf/ssl.key/server.key"
To:
<VirtualHost *:443>
...
SSLEngine on
SSLCertificateFile "/etc/letsencrypt/live/ploshop.co.in/fullchain.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/ploshop.co.in/privkey.pem"
Do not forget to restart apache.

I am trying to change the policy in RASA from max_history: 5 to FullDialogueTrackerFeaturizer

I am new to using RASA and I was able to follow this guide:
https://rasa.com/docs/rasa/user-guide/installation/
to set up RASA on Ubunto 18.04 on windows. I am now following a second guide:
https://rasa.com/docs/rasa/user-guide/rasa-tutorial/
and am at step 3, running the code in step 3 on Ubuntu cane back with the following result:
# Configuration for Rasa NLU.
# https://rasa.com/docs/rasa/nlu/components/
language: en
pipeline:
- name: WhitespaceTokenizer
- name: RegexFeaturizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
- name: CountVectorsFeaturizer
analyzer: "char_wb"
min_ngram: 1
max_ngram: 4
- name: DIETClassifier
epochs: 100
- name: EntitySynonymMapper
- name: ResponseSelector
epochs: 100
# Configuration for Rasa Core.
# https://rasa.com/docs/rasa/core/policies/
policies:
- name: MemoizationPolicy
- name: TEDPolicy
max_history: 5
epochs: 100
- name: MappingPolicy
Near the bottom, where it lists max_history: 5 I would like to change the policy to FullDialogueTrackerFeaturizer so that the entire dialog is considered for the bots production. I have tried reading this article:
https://rasa.com/docs/rasa/api/core-featurization/#featurization-conversations
although the article explains the function of the policy, I could not how to switch the policy.
My question is, how do I change the policy from max_history: 5 to FullDialogueTrackerFeaturizer?
FullDialogueTrackerFeaturizer is not a policy it's a featurizer. What you're describing is infinite max_history. This is not a good idea, as your model will become enormous and very slow. Instead, set max_history high enough to account for any patterns in your training data. If you need to save data for use at an arbitrary point in a conversation, set a slot instead.

Ansible - playbook calls another playbook with variables, tags, and limits

I have a blue green deploy playbook. It relies on certain variables to determine which hosts to apply the underlying roles. Here is one of the roles for an example:
- name: Remove current server from load balancer
hosts: 'tag_Name_{{server_name}}_production'
remote_user: ec2-user
sudo: true
roles:
- remove-load-balancer
I can call this playbook with specified limits and tags and it works wonderfully - but only for one type of server. For example, this command will blue green deploy our services servers:
ansible-playbook blue.green.yml -i ec2.py -l tag_Name_services_production,tag_Name_services_production_old --skip-tags=restart,stop -e server_name=services -e core_repo=~/core
I would like to write a master blue green playbook which essentially runs several playbooks - first for the api servers and then for the services servers. I have tried using includes but cannot seem to get the syntax right - ansible either complains that my task doesn't do anything or complains that the syntax is incorrect:
- name: Blue green deploy to all production boxes.
hosts: localhost
tasks:
- include: blue.green.single.yml
hosts:
- tag_Name_api_production
- tag_Name_api_production_old
vars:
- server_name: api
skip-tags:
- restart
- stop
- include: blue.green.single.yml
hosts:
- tag_Name_services_production
- tag_Name_services_production_old
vars:
- server_name: services
skip-tags:
- restart
- stop
Ideally I'd be able to call this like so:
ansible-playbook blue.green.yml -i ec2.py -e core_repo=~/core
Has anyone done this successfully? If so - how can I accomplish this?
Would this work for your case?
- name: Blue green deploy to all production boxes.
hosts: [tag_Name_api_production, tag_Name_api_production_old]
tasks:
- include: blue.green.single.yml
vars:
- server_name: api
skip-tags:
- restart
- stop
- name: Blue green deploy to all production boxes.
hosts: [tag_Name_services_production, tag_Name_services_production_old]
tasks:
- include: blue.green.single.yml
vars:
- server_name: services
skip-tags:
- restart
- stop

exit on ssh failure

in my play i ssh to a host and execute a number of roles, however if I fail to ssh into the instance the next include carry on regardless, id like to exit/fail when - build fails to execute
here is the example,
FYI - app_ec2 creates an instance on AWS and sets the host, build.yml then applies configuration to this instance and launch then users this instance to create an AMI and then a ASGroup
---
- hosts: localhost
connection: local
serial: 1
gather_facts: true
any_errors_fatal: true
max_fail_percentage: 0
vars_files:
- "vars/security.vars"
- "vars/{{ env }}/common.vars"
- "vars/server.vars"
roles:
- app_ec2
- include: build.yml
- include: launch-asg.yml
build.yml:
- hosts: "{{ role }}"
serial: 1
gather_facts: true
sudo: yes
any_errors_fatal: true
max_fail_percentage: 0
vars_files:
- "vars/{{ env }}/common.vars"
- "vars/server.vars"
roles:
- default
- restart
- awscli
- cloudwatch-logs
- ntp
- java
- tomcat
- newrelic
- newrelic_apm
- "{{role}}"
- app_liquibase
- restart
I am suggesting to use Ansible Blocks:
tasks:
- block:
- debug: msg='i execute normally'
- command: /bin/false
- debug: msg='i never execute, cause ERROR!'
rescue:
- debug: msg='I caught an error'
- command: /bin/false
- debug: msg='I also never execute :-('
always:
- debug: msg="this always executes"
And you can use this workaround:
Run some playbook on current host (-c local == local connection)
Call
inside some block run ansible that connects to remote host, and if
block fails retry.
PS:
Ansible playbooks should use Idempotency concept:
The concept that change commands should only be applied when they need
to be applied, and that it is better to describe the desired state of
a system than the process of how to get to that state. As an analogy,
the path from North Carolina in the United States to California
involves driving a very long way West but if I were instead in
Anchorage, Alaska, driving a long way west is no longer the right way
to get to California. Ansible’s Resources like you to say “put me in
California” and then decide how to get there. If you were already in
California, nothing needs to happen, and it will let you know it
didn’t need to change anything.

Resources