RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1227124 - Runcmd module doesn't run commands
Summary: Runcmd module doesn't run commands
Keywords:
Status: CLOSED INSUFFICIENT_DATA
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: cloud-init
Version: 7.1
Hardware: Unspecified
OS: Unspecified
unspecified
high
Target Milestone: rc
: ---
Assignee: Lars Kellogg-Stedman
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-06-02 00:30 UTC by William Brown
Modified: 2019-12-03 07:28 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-01-16 18:31:42 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description William Brown 2015-06-02 00:30:51 UTC
Description of problem:
I noticed that my environment which relies on runcmd for deployment, stopped working.

It would seem that in the latest release the runcmd module no longer actually runs commands. 

Adding the following code to the tail of cc_runcmd fixes the issue:

    try:
        env = os.environ.copy()
        iid = cloud.get_instance_id()
        if iid:
            env['INSTANCE_ID'] = str(iid)
        cmd = ['/bin/sh', out_fn]
        util.subp(cmd, env=env, capture=False)
    except:
        util.logexc(log, "Failed to run runcmd module %s", name)
        raise


Version-Release number of selected component (if applicable):
cloud-init-0.7.5-10

How reproducible:
Always

Steps to Reproduce:
1. Use cloud init with runcmd in an environment. Say:
runcmd:
- touch /tmp/TEST
2. Boot system
3. Check /tmp and /var/lib/cloud/instance/scripts/runcmd

Actual results:
The runcmd temp file is populated correctly, and has the correct data. Yet no test file was created.

Expected results:
The commands are run.

Comment 2 Lars Kellogg-Stedman 2015-06-06 02:00:24 UTC
I am unable to reproduce this behavior with cloud-init-0.7.5-1, which is the latest build of 0.7.5 for el7.  Using the RHEL 7.0 KVM guest image (which has cloud-init-0.7.5-1.el7_0.x86_64), and this user-data:

    #cloud-config
    runcmd:
    - touch /root/TEST
    - touch /tmp/TEST

After booting, both the files /tmp/TEST and /root/TEST exist.

I have also tried this using 0.7.6-2, which is available in the RHEL 7.1 cloud image, and that works as well.

There does not appear to be a cloud-init-0.7.5-10 anywhere.  Can you double check the version number of that package and confirm that it comes from a Red Hat repository?

Comment 3 vijaya.h 2019-12-03 07:28:13 UTC
Setup:
cloud-init 0.7.8
RHEL: rhel 7.6

Issue: commands under runcmd do not execute.

cloud-config:

            #cloud-config
            users:
              - name: demo
            chpasswd:
              list : |
                 demo:mydemo
              expire: False
            ssh_pwauth: True
            write_files:
              - path: /tmp/myfile.sh
                permissions: 0777
                owner: root
                content: |
                  #!/bin/bash
                  set -e
                  echo "hello world" >> /tmp/myfile.txt
            runcmd:
              - [ sh, -c, echo "=========hello world=========" ]
            final_message: "The system is finally up, after $UPTIME seconds"



The commands are present in runcmd. But I do not see any "hello world" printed. The final_message is seen on the console though.

[root@rhel-test scripts]# cat runcmd
#!/bin/sh
'sh' '-c' 'echo "=========hello world========="'

/var/log/messages:
Dec  3 02:22:21 localhost journal: [CLOUDINIT] helpers.py[DEBUG]: Running config-runcmd using lock (<FileLock using file '/var/lib/cloud/instances/d04710cf-88eb-4de3-ae56-86a9c5ae7ffc/sem/config_runcmd'>)
Dec  3 02:22:21 localhost journal: [CLOUDINIT] util.py[DEBUG]: Shellified 1 commands.
Dec  3 02:22:21 localhost journal: [CLOUDINIT] util.py[DEBUG]: Writing to /var/lib/cloud/instances/d04710cf-88eb-4de3-ae56-86a9c5ae7ffc/scripts/runcmd - wb: [448] 59 bytes
Dec  3 02:22:21 localhost journal: [CLOUDINIT] handlers.py[DEBUG]: finish: modules-config/config-runcmd: SUCCESS: config-runcmd ran successfully


Note You need to log in before you can comment on or make changes to this bug.