Copy file from .ebextentions folder - amazon-web-services

I want to file from .ebextentions/td-agent.conf to /etc/td-agent/td-agent.conf. But its not working and getting below error.
if you see attached image, there are 3 files in .ebextentions. I had put copy command in 01-main.config.
---
container_commands:
01_cron_job:
command: "touch /tmp/is_leader"
leader_only: true
01_tdconfcopy_job:
command: "yes | cp .ebextensions/td-agent.conf /etc/td-agent/td-agent.conf"
error is as given below
Command failed on instance. Return code: 1 Output: cp: cannot create regular file '/etc/td-agent/td-agent.conf': No such file or directory

The issue is you're copying a file to a directory that doesn't exist. You should create the output directory first and then copy config files.
So it would be:
---
container_commands:
01_cron_job:
command: "touch /tmp/is_leader"
leader_only: true
01_create_dir:
command: "sudo mkdir -p /etc/td-agent/"
02_tdconfcopy_job:
command: "yes | cp .ebextensions/td-agent.conf /etc/td-agent/td-agent.conf"
Alternatively, you could to create a file on the server directly with files command.
files:
"/etc/td-agent/td-agent.conf":
mode: "000644"
owner: root
group: root
content: |
content of your config file that you want to copy

Related

Evaluating ARGs in dockerfile

I am using dockerfile maven plugin to build the docker images. In pom.xml file, 3 args will be sent to the dockerfile. I have added my dockerfile here.
ARG PROJECT_BASE_DIR
ARG TOMCAT_JULI_ADAPTER_VERSION
ARG TOMCAT_JULI_VERSION
FROM tomcat:8.0-jre8
ADD ${PROJECT_BASE_DIR}/target/dependency/log4j-1.2.17.jar /usr/local/tomcat/lib/
ADD ${PROJECT_BASE_DIR}/target/dependency/ojdbc7-12.1.0.2.jar /usr/local/tomcat/lib/
ADD ${PROJECT_BASE_DIR}/target/dependency/tomcat-extras-juli ${TOMCAT_JULI_ADAPTER_VERSION}.jar /usr/local/tomcat/lib/
ADD ${PROJECT_BASE_DIR}/target/dependency/tomcat-juli-${TOMCAT_JULI_VERSION}.jar /usr/local/tomcat/bin/
ADD ${PROJECT_BASE_DIR}/configuration/log4j.properties /usr/local/tomcat/lib/
ADD ${PROJECT_BASE_DIR}/configuration/server.xml /usr/local/tomcat/conf/
ADD ${PROJECT_BASE_DIR}/scripts/setenv.sh /usr/local/tomcat/
RUN chmod +x setenv.sh
RUN rm /usr/local/tomcat/conf/logging.properties
EXPOSE 8080
ENTRYPOINT [ "sh", "-c", "./setenv.sh" ]
pom.xml file
<configuration>
<repository>${docker.image.name}</repository>
<tag>${project.version}</tag>
<buildArgs>
<PROJECT_BASE_DIR>${project.basedir}</PROJECT_BASE_DIR>
<TOMCAT_JULI_VERSION>${tomcat-juli.version}</TOMCAT_JULI_VERSION>
<TOMCAT_JULI_ADAPTER_VERSION>${tomcat-juli-adapters.version}</TOMCAT_JULI_ADAPTER_VERSION>
</buildArgs>
</configuration>
When this is run, It won't take the value in ${TOMCAT_JULI_VERSION} and ${TOMCAT_JULI_ADAPTER_VERSION} but ${PROJECT_BASE_DIR} value is taken. I'm getting following error.
ADD failed: stat
/var/lib/docker/tmp/docker-builder537359917/target/dependency/tomcat-extras-juli-.jar:
no such file or directory

Script execution using ansible [duplicate]

I am using Ansible to deploy my project and I trying to check if an specified package is installed, but I have a problem with it task, here is the task:
- name: Check if python-apt is installed
command: dpkg -l | grep python-apt
register: python_apt_installed
ignore_errors: True
And here is the problem:
$ ansible-playbook -i hosts idempotent.yml
PLAY [lxc-host] ***************************************************************
GATHERING FACTS ***************************************************************
ok: [10.0.3.240]
TASK: [idempotent | Check if python-apt is installed] *************************
failed: [10.0.3.240] => {"changed": true, "cmd": ["dpkg", "-l", "|", "grep", "python-apt"], "delta": "0:00:00.015524", "end": "2014-07-10 14:41:35.207971", "rc": 2, "start": "2014-07-10 14:41:35.192447"}
stderr: dpkg-query: error: package name in specifier '|' is illegal: must start with an alphanumeric character
...ignoring
PLAY RECAP ********************************************************************
10.0.3.240 : ok=2 changed=1 unreachable=0 failed=0
Why is illegal this character '|' .
From the doc:
command - Executes a command on a remote node
The command module takes the command name followed by a list of
space-delimited arguments. The given command will be executed on all
selected nodes. It will not be processed through the shell, so
variables like $HOME and operations like "<", ">", "|", and "&" will
not work (use the shell module if you need these features).
shell - Executes a commands in nodes
The shell module takes the command name followed by a list of space-delimited arguments.
It is almost exactly like the command module but runs the command
through a shell (/bin/sh) on the remote node.
Therefore you have to use shell: dpkg -l | grep python-apt.
read about the command module in the Ansible documentation:
It will not be processed through the shell, so .. operations like "<", ">", "|", and "&" will not work
As it recommends, use the shell module:
- name: Check if python-apt is installed
shell: dpkg -l | grep python-apt
register: python_apt_installed
ignore_errors: True
For what it's worth, you can check/confirm the installation in a debian environment using the apt command:
- name: ensure python-apt is installed
apt: name=python-apt state=present

Remove old crons when redeplying to AWS beanstack

Not an expert on AWS and trying to fool around with Cron jobs. For testing, I had a sample script send me emails every minute. Now, I want to change it to once every 10 minutes (*/10 * * * *) These are the container commands I tried and none of them seems to work.
I am using a config file and a txt file to define the crons.
Config file contents (with various ideas I read from online sources)
container_commands:
00_remove_old_cron_jobs0:
command: "rm -fr /etc/cron.d/cron_job"
01_remove_old_cron_jobs1:
command: "sudo sed -i 's/empty stuff//g' /etc/cron.d/cron_job"
02_remove_old_cron_jobs2:
command: "crontab -r || exit 0"
03_cron_job:
command: "cat .ebextensions/cron_job.txt > /etc/cron.d/cron_job && chmod 644 /etc/cron.d/cron_job"
leader_only: true
cron_job.txt file contents.
# The newline at the end of this file is extremely important. Cron won't run without it.
0 * * * * ec2-user /usr/bin/php -q /var/www/html/cron1.php > /dev/null
0 * * * * ec2-user /usr/bin/php -q /var/www/html/html/cron2.php > /dev/null
*/10 * * * * ec2-user /usr/bin/php -q /var/www/html/cronTestEmailer.php > /dev/null
The test emailer script keeps firing every minute instead of every 10 mins and I dont know how I can make sure cron updates are reflected correctly.
You can achieve the same with the follow ebextensions config file.
files:
"/etc/cron.d/mycron":
mode: "000644"
owner: root
group: root
content: |
* * * * * root /usr/local/bin/myscript.sh
"/usr/local/bin/myscript.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
date > /tmp/date
# Your actual script content
exit 0
commands:
remove_old_cron:
command: "rm -f /etc/cron.d/*.bak"
More Details about the config file below:
files: Creates a Cron job and a file with the name myscript.sh. If a file with the same name exists already, first it moves the old file .bak and creates the file with new contents.
commands: deletes the all .bak files

How to collect a grep and use it in a aws configset

In my aws Cloud Formation cfn configset I have a command to set an environment key to the name of the user group apache belongs to as it might be apache or www-data depending on the distro.
Something like this:
Metadata:
AWS::CloudFormation::Init:
configSets:
joomla:
- "set_permissions"
- "and_some_more..."
configure_cfn:
files:
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
content: !Sub |
[cfn-auto-reloader-hook]
triggers=post.update
path=Resources.EC2.Metadata.AWS::CloudFormation::Init
action=/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource EC2 --configsets joomla --region ${AWS::Region}
mode: "000400"
owner: root
group: root
.....
set_permissions:
commands:
01_01_get_WebServerGroup:
env:
#webserver group might be apache or www-data depending on the distro
WebServerGp:
command: "ps -ef | egrep '(httpd|apache2|apache)' | grep -v `whoami` | grep -v root | head -n1 | awk '{print $1}'"
However, when I launch this stack, the configsets process halts at this point and I get an an error in the cfn_init.log that looks like this:
File
"/usr/lib/python2.7/dist-packages/cfnbootstrap/command_tool.py", line
80, in apply
raise ToolError(u"%s does not specify the 'command' attribute, which is required" % name) ToolError: 01_01_get_WebServerGroup does
not specify the 'command' attribute, which is required
Is this the preferred method to catch and use a grep result in a configset command? Is there a better way? What can I do to address the error thrown in the cfn_init.log?
OK, I guess I can create parameter and mapping elements to capture the distro type on launch and then set the webserver group accordingly but I am really trying to understand how to set the env: key to a response from the cli.
The problem of your code is this line WebServerGp.
Line command is must be on the same level of env, under the commands name, in your case is 01_01_get_WebServerGroup. So, it has to be like this:
commands:
01_01_get_WebServerGroup:
env: ..
command: ..
If you want to use the result of grep, you can put them on variable and use it later.
You can specify more than one command under that command line using \n for executing the command.
Please check this code below.
command: "result=(ps ef | grep ...)\n echo $result\n ..."
If you have really long command, you can use the Fn::Join to be the value of command.

Command cron_01_set_leader output: bash: /usr/local/bin/bundle: No such file or directory

After installing/configuring whenever-elasticbeanstalk gem, I'm seeing the following error in /var/log/cfn-init.log on my EC2 instance after running git aws.push from my local repo.
Iam using aws elastic benastalk with rails 4.
2014-10-21 08:08:37,602 [DEBUG] Running test for command cron_01_set_leader
2014-10-21 08:08:37,744 [DEBUG] Test command output:
2014-10-21 08:08:37,745 [DEBUG] Test for command cron_01_set_leader passed
2014-10-21 08:08:38,085 [ERROR] Command cron_01_set_leader (su -c "/usr/local/bin/bundle exec create_cron_leader --no-update" $EB_CONFIG_APP_USER) failed
2014-10-21 08:08:38,086 [DEBUG] Command cron_01_set_leader output: bash: /usr/local/bin/bundle: No such file or directory
Traceback (most recent call last):
I have added the whenever-elasticbeanstalk
Below is my cron.config file content..
Any idea ...what am i doing wrong?
files:
# Reload the on deployment
/opt/elasticbeanstalk/hooks/appdeploy/post/10_reload_cron.sh:
mode: "00700"
owner: root
group: root
content: |
#!/usr/bin/env bash
. /opt/elasticbeanstalk/containerfiles/envvars
cd $EB_CONFIG_APP_CURRENT
su -c "/usr/local/bin/bundle exec setup_cron" $EB_CONFIG_APP_USER
# Add Bundle to the PATH
"/etc/profile.d/bundle.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
export PATH=$PATH:/usr/local/bin
encoding: plain
container_commands:
cron_01_set_leader:
test: test ! -f /opt/elasticbeanstalk/containerfiles/.cron-setup-complete
leader_only: true
cwd: /var/app/ondeck
command: su -c "/usr/local/bin/bundle exec create_cron_leader --no-update" $EB_CONFIG_APP_USER
cron_02_write_cron_setup_complete_file:
cwd: /opt/elasticbeanstalk/containerfiles
command: touch .cron-setup-complete
Which solution stack are you using? Can you give the exact name, something like "64bit Amazon Linux 2014.03 v1.0.9 running Ruby 2.1 (Puma)".
I think you will need to replace "/usr/local/bin/bundle" with the actual version of bundle that is used for the solution stack.
Can you just try using "bundle" instaed of "/usr/local/bin/bundle"?