augeas not recognizing file in tmp directory - amazon-ec2

I am having issue with Augeas on my redhat ec2. I recently started using this API, so far used only for changes in /etc/ directory.
Here is OS that I used.
OS: Red Hat Enterprise Linux Server release 6.4 (Santiago)
what I have found recently is augtool is not recognizing any files other than files in /etc/ and /boot/.
for example:augtool> print /files/tmp/sample/test.cfg will not give any result.
test.cfg
[Credentials]
Keys = True
For testing purposes I moved this file from /tmp/ to /etc/httpd/conf.d/, but augeas still not printing contents of it. Where are it print config tree of my apache config file.
I am trying to put them in puppet, here is my code:
augeas {"changeTest" :
context => "/files/tmp/sample/test.cfg",
changes => "set Credentials/Keys False"
}
This is what I saw in my puppet debug:
Debug: Augeas[changeTest](provider=augeas): sending command 'set' with params ["/files/tmp/sample/test.cfg/Credentials/Keys", "False"]
Debug: Augeas[changeTest](provider=augeas): Skipping because no files were changed
What I am doing wring here?

Augeas doesn't "recognize" files, or knows the standard paths of these files. /tmp is not a standard location for any configuration file, so augeas cannot know what to do.
In Puppet, you can tell augeas which lens (I.e. parser) to use for a given file:
augeas {"changeTest" :
incl => "/tmp/sample/test.cfg",
lens => "Httpd.lns",
changes => "set Credentials/Keys False",
}

Related

GrumPHP and php-cs-fixer on WSL using wrong version

I'm trying to get GrumPHP to work with a small Laravel 9 project but php-cs-fixer is being pulled from the wrong location and I can't seem to find how to change this.
Error from GrumPHP:
phpcsfixer
==========
PHP needs to be a minimum version of PHP 7.1.0 and maximum version of PHP 7.4.*.
You can fix errors by running the following command:
'/windir/f/wamp64/vendor/bin//php-cs-fixer' '--config=./home/testuser/php-cs-config.php_cs' '--verbose' 'fix'
Seems like an easy fix, so I updated php-cs-fixer and followed the upgrade guide to get to v3. (currently sitting on 3.10). But I can also see that '/windir/f/wamp64/vendor/bin//php-cs-fixer' is not the correct directory for php-cs-fixer, the actual bin folder is located in WSL not the windows directory so I included a GRUMPHP_BIN_DIR in the grumphp yaml but still no luck.
grumphp.yml
grumphp:
environment:
variables:
GRUMPHP_PROJECT_DIR: "."
GRUMPHP_BIN_DIR: "./home/testuser/tools/vendor/bin/"
paths:
- './home/plustime/tools'
tasks:
phpcsfixer:
config: "./home/testuser/php-cs-config.php_cs"
allow_risky: ~
cache_file: ~
rules: []
using_cache: ~
config_contains_finder: true
verbose: true
diff: false
triggered_by: ['php']
I can't seem to find much about this or anything in the docs, so any help would be appreciated.
This ended up coming down to altering how WSL constructs the environment. To get around WSL building windows paths into the Linux distribution.
The answer was found here:
How to remove the Win10's PATH from WSL
Quick run down:
On the WSL instance open the file /etc/wsl.conf with something like
sudo nano /etc/wsl.conf
Add the following lines to the bottom of the file,
[interop]
appendWindowsPath = false
Mine looked like this when it was finished:
# Enable extra metadata options by default
[automount]
enabled = true
root = /windir/
options = "metadata,umask=22,fmask=11"
mountFsTab = false
# Enable DNS – even though these are turned on by default, we'll specify here just to be explicit.
[network]
generateHosts = true
generateResolvConf = true
[interop]
appendWindowsPath = false
Then restart the WSL instance from your windows terminal and restart it.
wsl --shutdown
GrumPHP now using the correct php-cs-fixer.

Ansible Error reading config file: File contains no section headers

SUMMARY
As per documentation for Ansible Configuration Settings, we can place ansible.cfg in current directory of the project we are working on and Ansible will search for a config file in the order specified in link above.
However, it appears that ansible is unable to correctly parse ansible.cfg file within my project directory. I am not sure but I think it has to be with the Ini ConfigParser
ANSIBLE VERSION
ansible 2.6.3
config file = /Users/pnotes/Code/Terraform/Blog/ansible/ansible.cfg
configured module search path = ['/Users/pnotes/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/pnotes/.pyenv/versions/3.6.4/lib/python3.6/site-packages/ansible
executable location = /Users/pnotes/.pyenv/versions/3.6.4/bin/ansible
python version = 3.6.4 (default, Feb 26 2018, 21:07:35) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
CONFIGURATION
output of "ansible-config dump --only-changed"
Error reading config file (/Users/pnotes/Code/Terraform/Blog/terraform/ansible.cfg): File contains no section headers.
file: '/Users/pnotes/Code/Terraform/Blog/terraform/ansible.cfg', line: 3
'vault_password_file = ~/.vault_pass.txt\n'
OS / ENVIRONMENT
macOS High Sierra
contents of terraform/ansible.cfg:
# If set, configures the path to the Vault password file as an
# alternative to specifying --vault-password-file on the command
# line.
vault_password_file = ~/.vault_pass.txt
n
Note: when project_directory/terraform/ansible.cfg is commented out, ansible uses ~/.ansible.cfg and is able to decrypt encrypted files.
EXPECTED RESULTS
I expect playbook to decrypt all encrypted vars using the ansible vault password saved in the path provide in the configuration file (ansible.cfg) provided in the project directory.
ACTUAL RESULTS
I get the error below:
Error: Error applying plan:
1 error(s) occurred:
* linode_linode.base: Error running command 'sleep 30; ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root --ask-pass -i '172.104.29.185,' ../ansible/provision.yml --extra-vars 'ip=000.111.22.185' -vvvv': exit status 5. Output: Error reading config file (/Users/pnotes/Code/Terraform/Test/terraform/ansible.cfg): File contains no section headers.
file: '/Users/pnotes/Code/Terraform/Test/terraform/ansible.cfg', line: 3
'vault_password_file = ~/.vault_pass.txt\n'
Can someone please explain why I keep getting the error **exit status 5. Output: Error reading config file (/Users/pnotes/Code/Terraform/Test/terraform/ansible.cfg): File contains no section headers.
I also tried looking for info on how ansible generates the default /etc/ansible.cfg file but can't seem to track it down (I use python in a limited capacity so this might be why I am having a hard time with this)
Would really appreciate it.
ansible.cfg is supposed to be divided into sections with headers of the form [section_name]. The vault_password_file option, like the majority of the configuration options, belongs to the [defaults] section, so your ansible.cfg needs to look like:
[defaults]
vault_password_file = ~/.vault_pass.txt

Ansible archive module "no action detected in task"

I want to use the archive module of ansible but it is unfortunately not working. I have the following version installed: ansible 2.3.0 (devel 2131eaba0c)
my playbook looks like this:
- archive: path="{{path_dir}}" dest="{{dest_dir}}/foo.zip" format=zip
The output looks like this:
"failed": true, "reason": "no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/prj/sndbox1/app/jenkins/jobs/release/workspace/tasks/build_rpclient.yml': line 125, column 3, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- archive: path="{{path_dir}}" dest="{{dest_dir}}/foo.zip" format=zip
^ here
We could be wrong, but this one looks like it might be an issue with missing quotes. Always quote template expression brackets when they start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}"
As far as I understood the doc, the extra modules are shipped within ansible, so I assume I don't need to separately install this module.
However, what am I doing wrong? Is there any configuration I need to change in order to tell ansible where to look for the extra modules?
Thanks in advance!
Edit: Included the the full log message
Edit 2:
I tried to put the archive.py directly into my working directory --> [library]/archive.py
Now I get the following error:
"failed": true, "msg": "Could not find imported module support code for archive. Looked for either get_exception or pycompat24"
I have the same use case here, I'm using Ansible version 2.2.0.0. Installed via brew on MacOS sierra.
I've managed to solve the issue by adding the following into my local ansible.cfg file.
On defautls section, you must change the library entry:
[defaults]
library = /usr/local/Cellar/ansible/2.2.0.0_2/libexec/lib/python2.7:library
If you have a different setup, check:
pip show ansible
/usr/share/ansible if you are on Linux machine.

puppet staging::deploy is not working on windows and saying unzip command not found

I am using staging::deploy in my puppet script to download and extract the file as below. And I am trying this on windows.
staging::deploy{ "jdk1.7.0_04.zip":
source => 'http://sometlocation/jdk1.7.0_04.zip',
target => 'E:/PuppetTestData',
}
File download is happening but when staging::extract is executed, I am getting below error.
Error: Could not find command 'unzip'
I have installed unzip.exe on my windows local but still I am getting the same error.
Could anyone suggest me the solution for this problem?
Make sure that unzip.exe file is added to PATH on your Windows.
staging::deploy makes use of facter fact path :
Exec{
path => $::path,
...
}
to setup search path used for command execution. Here you find more about path parameter in exec resource.

Keep Ansible DRY: How to avoid repeating variables?

Recently just started using Ansible and I have run into a problem. In one of my YAML structures I have defined something like this:
---
# file: main.yml
#
# Jenkins variables for installation and configuration
jenkins:
debian:
# Debian repository containing Jenkins and the associated key for accessing the repository
repo: 'deb http://pkg.jenkins-ci.org/debian binary/'
repo_key: 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key'
# Dependencies needed for Jenkins to run properly
dependencies:
- 'openjdk-7-jdk'
- 'git-core'
- 'curl'
port: 8080
# Installation directory
home: '/opt/jenkins'
# Path to the location of the main Jenkins-cli binary
bin_path: '{{jenkins.home}}/jenkins-cli.jar'
# Path to the location of the Jenkins updates file
updates_path: '{{jenkins.home}}/updates_jenkins.json'
Ansible gives me an error like this from a specific task:
"recursive loop detected in template string:
{{jenkins.home}}/updates_jenkins.json"
I've narrowed it down to the problem being with the fact bin_path and updates_path both refer to 'home'. Is there a way around this? It kind of sucks that I would need to define '/opt/jenkins' multiple times.
As far as I know that this is a limitation of jinja2 variables. it was working with the old ${} and broke since 1.4. I am not sure if they fixed that in 1.5.
My temp solution would be removing home from the "jenkins"
---
# file: main.yml
#
# Jenkins variables for installation and configuration
# Installation directory
jenkins_home: '/opt/jenkins'
jenkins:
debian:
# Debian repository containing Jenkins and the associated key for accessing the repository
repo: 'deb http://pkg.jenkins-ci.org/debian binary/'
repo_key: 'http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key'
# Dependencies needed for Jenkins to run properly
dependencies:
- 'openjdk-7-jdk'
- 'git-core'
- 'curl'
port: 8080
# Path to the location of the main Jenkins-cli binary
bin_path: '{{jenkins_home}}/jenkins-cli.jar'
# Path to the location of the Jenkins updates file
updates_path: '{{jenkins_home}}/updates_jenkins.json'
This should do it:
bin_path: "{{ jenkins['home'] }}/jenkins-cli.jar"

Resources